本文介绍了接近查询的Yii Emongodocuments忽略maxDistance的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用$附近找到靠近我的用户的地方。

  $ places = Places :: model() - > findAll(array(
conditions=> array('b'''location'=> Array('near'=> array((float)$ this-> latitudeUser,(float)$ this-> longitudeUser)),
),
maxDistance=> 1,
limit=> 5,
));

除了找到德克萨斯美国的地方和我在加拿大蒙特利尔的地方外,我不知道我能做些什么来使maxDistance发挥作用。看来我不能使用GeoNear或NearSphere,因为EMongoDocuments似乎不支持它们。



所以我错过了一些明显的东西?

我知道但没有任何帮助。



编辑:改变经度的方向

解决方案

引用mongolabs中的奇妙人物:
我相信你需要将maxDistance放在$ near条件中。例如:

  $ places = Places :: model() - > findAll(array(
)conditions =>数组(
'location'=> Array('near'=> array((float)$ this-> latitudeUser,(float)$ this-> longitudeUser),'maxDistance' = 1),
),
限制=> 5,
));

我对这个框架并不熟悉,所以我不完全确定这是否正确,但是我根据相应的MongoDB查询的正确语法:

  db.places.find({location:{$ near :[50,50],$ maxDistance:5}}).limit(5)


$ b

maxDistance与$ near的条件相同。试一试,让我们知道它是否有帮助。
谢谢,


I am trying to use $near to find places that are near my users.

    $places = Places::model ()->findAll(array (
            "conditions" => array (
                'location' => Array('near' => array((float)$this->latitudeUser,(float)$this->longitudeUser)),
            ),
            "maxDistance" => 1,
            "limit" => 5,
        ));

Everything seems to work except that it finds places as far as Texas USA and I am in Montreal Canada. I have no idea what I can do to make maxDistance work. It seems I cannot use GeoNear or nearSphere since EMongoDocuments does not support them it seems.

So am I missing something obvious?

I am aware of mongomapper-near-with-maxdistance-mongooperationfailure-geo-values-have-to but nothing there helped.

edit: changed order of longitude lattitude

解决方案

Quoting the fantastic guy's at mongolabs:I believe you need to put maxDistance inside the $near conditional. Something like this:

$places = Places::model ()->findAll(array (
"conditions" => array (
'location' => Array('near' => array((float)$this->latitudeUser,(float)$this->longitudeUser), 'maxDistance' => 1),
),
"limit" => 5,
));

I'm not familiar with this framework so I'm not completely sure if that's right, but I'm basing this on the proper syntax for the equivalent MongoDB query:

db.places.find( { location : { $near : [50,50] , $maxDistance : 5 } } ).limit(5)

Notice $maxDistance is inside the same condition as $near. Give that a try and let us know if it helps.Thanks,

这篇关于接近查询的Yii Emongodocuments忽略maxDistance的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 10:40