Start a new topic

Max distance for _geoloc/$nearsphere

What is the unit for the $maxDistance parameter on geo based queries? I'm using the following math but I'm not sure if it's right:



metersToMiles = 0.000621371;

maxDistance = radiusInKilometers * 1000 * metersToMiles / 3963.192;



For example, for a radius of 15km the query body is the following:



{"_geoloc":{"$nearSphere":[-46.683750199999999,-23.594244364991852],"$maxDistance":0.0023517822846770287}}



any help?

thanks

Neto, are you using the REST API or this with business logic?
Hi Michael! I'm using both collection hook and iOS Framework
When using the iOS library (or the REST API) specify maxDistance in miles. When using business logic, such as with a collection hook, the maxDistance is specified in radians. (http://stackoverflow.com/questions/3878702/mongodb-bound-queries-how-do-i-convert-mile-to-radian might be helpful)
Login or Signup to post a comment