我使用MongoDB来存储GPS位置数据,格式为GeoJSON文档:
{"type" : "Point", "coordinates" : [33.313183, 44.465632]}
{"type" : "Point", "coordinates" : [33.2926487, 44.4159651]}
更新:我还保证了2dsphere索引如下:
db.test.ensureIndex( { loc : "2dsphere" } )
我从Google地图得到了坐标。现在,如果我使用这个命令进行搜索,我无法将结果中的距离转换为公里。
db.runCommand({geoNear: 'test', spherical: true, near: {type: "Point" , coordinates: [33.2926487, 44.4159651]}})
结果如下:
"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
]
}
}
}
]
第一个结果预期为零,因为它与源坐标和目标坐标相同,但仍有值。
我无法将第二个值转换为公里,在谷歌距离计算器中约为5.26公里。