When I run this query on MongoDB, I get all the places in the immediate vicinity of 500 miles to the specified coordinates. But I want to know the exact distance between the specified coordinates and the location of the result.
db.new_stores.find({ "geometry": { $nearSphere: { $geometry: { type: "Point", coordinates: [ -81.093699, 32.074673 ] }, $maxDistance: 500 * 3963 } } } ).pretty()
My output looks like this:
{ "_id" : ObjectId("565172058bc200b0db0f75b1"), "type" : "Feature", "geometry" : { "type" : "Point", "coordinates" : [ -80.148826, 25.941116 ] }, "properties" : { "Name" : "Anthony Coal Fired Pizza", "Address" : "17901 Biscayne Blvd, Aventura, FL" } }
I also want to know the distance of this place from the specified coordinate. I created a 2dsphere index on geometry.
source share