I use mongoDB to store GPS location data like this GeoJSON document
{"type": "Point", "coordinates": [33.313183, 44.465632]}
{"type": "Point", "coordinates": [33.2926487, 44.4159651]}
Update: I also provided a 2dspher index, e.g.
db.test.ensureIndex( { loc : "2dsphere" } )
I got the coordinates from Google maps. Now, if I use this command, I can’t convert the resulting distances to kilometers
db.runCommand({geoNear: 'test', spherical: true, near: {type: "Point" , coordinates: [33.2926487, 44.4159651]}})
The result is as follows:
"results" : [
{
"dis" : 0.0033427770982422957,
"obj" : {
"_id" : ObjectId("54a96f348fa05fcaed637a22"),
"loc" : {
"type" : "Point",
"coordinates" : [
33.2926487,
44.4159651
]
}
}
},
{
"dis" : 5764.7060911604085,
"obj" : {
"_id" : ObjectId("54a96f4c8fa05fcaed637a23"),
"loc" : {
"type" : "Point",
"coordinates" : [
33.313183,
44.465632
]
}
}
}
]
it is expected that the first result will be zero, since its the same point that I want to get the distance from the source = destination coordinates, but it still matters.
the second value, which I can’t convert to kilometers, in Google’s distance calculator is about 5.26 km.