Pymango geo2d聚合结果以什么单位返回

2024-06-25 05:20:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我的mongodb收藏中有以下记录

/* 1 */
{
    "_id" : ObjectId("58ecf141624bc0798ee5882d"),
    "username" : "user.sthlm",
    "location" : [ 
        18.0686, 
        59.3293
    ]
}

/* 2 */
{
    "_id" : ObjectId("58ecf141624bc0798ee5882e"),
    "username" : "user.malmo",
    "location" : [ 
        13.0038, 
        55.605
    ]
}

/* 3 */
{
    "_id" : ObjectId("58ecf141624bc0798ee5882f"),
    "username" : "user.la",
    "location" : [ 
        -118.2437, 
        34.0522
    ]
}

“location”是一个“2dsphere”类型,它的顺序是[经度,纬度]

现在我使用一个pymongo查询来检索给定点之间的距离

(斯德哥尔摩坐标) 经度=18.0686 纬度=59.3293

for doc in self.users.aggregate([{"$geoNear": {"near": [longitude, latitude],
                                                           "distanceField":"distance",
                                                           "distanceMultiplier": 1.0,
                                                           "num": int(count),
                                                           "spherical": True}}]):

结果如下

  {
      "distance": 0,
      "username": "user.sthlm"
    },
    {
      "distance": 0.08048218816530191,
      "username": "user.malmo"
    },
    {
      "distance": 1.393869662777678,
      "username": "user.la"
    }

在查询响应中,斯德哥尔摩和洛杉矶之间的距离返回为1.393869662777678。我不太清楚它在哪个单位

从谷歌地图上看,坐标之间的距离是8875公里或5515英里,1.3938不符合这两项法案。在mongoDB文档中,我提到结果不是以弧度返回的。所以我想知道从我的查询回复中可以得到什么

谢谢


Tags: id距离类型mongodb记录usernamelocationla