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
EMongoCriteria in YiiMongoDbSuite changes the mongo operators' char case, maxDistance will turn into "$maxdistance", then the mongodb server will ignore it and return all 100 items near the user's location. To use MongoYii, it will not change your query conditions: http://sammaye.github.io/MongoYii/
Quoting the fantastic guy's at mongolabs: I believe you need to put maxDistance inside the $near conditional. Something like this:
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:
Notice $maxDistance is inside the same condition as $near. Give that a try and let us know if it helps. Thanks,
MongoDB wants coordinates in the format : latitude, longitude. Your array has it the wrong way around. The distance should be in degrees, unless you use nearSphere. The results from nearSphere should be similar than to near, so EMongoDocuments should support. In case you use nearSphere, the maxdistance is in radians, so divide the distance (in km) by the radius of the Earth (in km, ~6371), if you use that.