【问题标题】:What is wrong with this function, that should make a geospatial query in mongo db?这个函数有什么问题,应该在 mongodb 中进行地理空间查询?
【发布时间】:2014-01-21 22:13:19
【问题描述】:

我有这个在 mongodb - php 中进行地理空间查询的函数。我不知道为什么,但它没有返回任何东西。 (我有一个名为 EVENTS 的集合,其中有一个包含两个字段经度、纬度的数组,并且我有用户位置坐标)。我想查询用户位置(1000 m 距离)附近的事件。你知道它有什么问题吗?

public function findEventsByUsersLocation($lng, $lat){
    $c_events = $this->db->events;
    $c_events->find(array('lnglat'=> array('$near'=>array($lng, $lat),
                                    '$maxDistance' => 1000)));
}

【问题讨论】:

  • 也许,您应该在$c_events->find() 之前添加return? :)

标签: php mongodb geospatial


【解决方案1】:

我不得不把退货。奥列格在写!

public function findEventsByUsersLocation($lng, $lat){
$c_events = $this->db->events;
return $c_events->find(array('lnglat'=> array('$near'=>array($lng, $lat),
                                '$maxDistance' => 1000)));

}

【讨论】:

    猜你喜欢
    • 2011-12-06
    • 2013-10-22
    • 1970-01-01
    • 2015-06-07
    • 1970-01-01
    • 2012-10-06
    • 1970-01-01
    • 2011-09-29
    • 2011-10-13
    相关资源
    最近更新 更多