基于Lat / Long和distance检索和显示laravel中的mongodb文档内容

时间:2016-01-19 07:45:52

标签: mongodb laravel laravel-5

1)在我的表中,基于纬度/长度和距离的几条记录我     获得记录。

 db.user_address.find({location: { $nearSphere: { $geometry: { type:
    "Point", coordinates: [74.365484,31.516063] }, $maxDistance:
    100}}}).pretty()

但同时我为什么要使用laravel来显示所有内容 记录。

$r = array('location'=>array( '$near' => array('$geometry' => array(
'type' => "Point", 'coordinates' => array(74.365484,31.516063)), 
'maxDistance' => 100 )));
            $ProviderInRange = UserAddress::where($r)->get();

请帮助我使用laravel来mongodb获取记录。

1 个答案:

答案 0 :(得分:0)

你必须改变一些文字,

$r = array("location"=> 
            array( "$near" => 
                    array("$geometry" => 
                            array( "type" => "Point", 
                                   "coordinates" => array(74.365484,31.516063)), 
                                   "$maxDistance" => 100 ))); 

$ProviderInRange = UserAddress::where($r)->get();

它工作正常。请看一下See Here