我有一个基于2dsphere(球形)的geonear查询返回距离。我不完全确定返回的单位指标。是米还是弧度?哪个"乘数"我应该用英里来获取距离吗?我在这个问题上找到的答案都有所不同。
答案 0 :(得分:0)
结果通常以弧度返回
查询:
db.runCommand( {
geoNear: "restaurants" ,
near: [ -73.93414657, 40.82302903 ],
spherical: true,
} )
会给出这样的结果:
{
"dis" : 0.0001360968348384049,
"obj" : {
"_id" : ObjectId("55cba2476c522cafdb054fee"),
"location" : {
"coordinates" : [
-73.94387689999999,
40.8255961
],
"type" : "Point"
},
"name" : "Texas Star Snack Bar"
}
}
所以在这种情况下,距离是半径,我们需要:
1. multiply it by 3963.2 to get distance in miles (in example we have 0.539 M)
2. multiply it by 6371 to get distance in kilometers (in example we have 0.867 km)
如果您使用的是3.2并且使用minDistance和maxDistance进行查询(按照米的定义) - 提供的距离以米为单位
db.runCommand(
{
geoNear: "restaurants",
near: { type: "Point", coordinates: [ -73.9667, 40.78 ] },
spherical: true,
minDistance: 3000,
maxDistance: 7000
}
)
和示例结果:
{
"dis" : 338.44550608396395,
"obj" : {
"_id" : ObjectId("55cba2476c522cafdb0561eb"),
"location" : {
"coordinates" : [
-73.9653551,
40.7828647
],
"type" : "Point"
},
"name" : "(Public Fare) 81St Street And Central Park West (Delacorte Theatre)"
}}
有一个很好的关于here数据集的教程 - 你无法用于测试。