geospatial - MongoDB Bound Queries: How do I convert mile to radian? -
i have collection of stores geospacial index on location propery.
what trying given user's latitude, latitude , search radius (mi), want return list of stores within parameters.
i saw following example on mongodb documentation (http://www.mongodb.org/display/docs/geospatial+indexing), looks distance in radians.
center = [50, 50] radius = 10 db.places.find({"loc" : {"$within" : {"$center" : [center, radius]}}})
so, formula convert miles radians?
solution awesome people @ mongodb-user helped me find answer. basically, looking way limit distance.
per, updated documentation, there 3rd parameter $near query: can use $near maximum distance
db.places.find( { loc : { $near : [50,50] , $maxdistance : 5 } } ).limit(20)
the value $maxdistance in radians; so, had take distance in miles , divide 69.
thank you!
as docs say:
all distances use radians. allows multiply radius of earth (about 6371 km or 3959 miles) distance in choice of units. conversely, divide radius of earth when doing queries.
so simple need divide radius earth radius. in example be:
radius = 10/3959
Comments
Post a Comment