我正在使用 MongoDB 执行以下原始查询:
qry = {"position" : SON([("$near", [52.497309,13.39385]), ("$maxDistance", distance/111.12 )])}
locations = Locations.objects(__raw__=qry)
数据库中的位置设置为
[52.473266, 13.45494]
。一旦我将距离设置为 7.3 或更高,我就会得到结果,所以两个位置之间的距离似乎至少为 7.3 公里。
当我用 Google Maps 计算这两个地理位置的距离(例如开车)时,它告诉我它们之间的距离只有 5.2 公里。
我用不同位置的负载进行了测试,google和mongodb的距离计算总是有很大差异
我是否遗漏了任何东西,或者有人可以解释一下这种差异的来源吗?
我已经检查过 this answer 但它对我不起作用......
最佳答案
MongoDB 假定坐标采用 (long, lat)
格式。如果您使用 Great-circle distance 手动计算距离,您将看到发生了什么:
> from math import acos, sin, cos, radians
>
> long_x, lat_x = [radians(y) for y in [52.473266, 13.45494]]
> long_y, lat_y = [radians(y) for y in [52.497309, 13.39385]]
>
> acos(sin(lat_x) * sin(lat_y) + cos(lat_x) * cos(lat_y) * cos(long_x - long_y)) * 6371.0
7.27362435031
Google 采用
(lat, long)
格式的坐标,因此如果您提供相同的输入,Google 解释将如下所示:> acos(sin(long_x) * sin(long_y) + cos(long_x) * cos(long_y) * cos(lat_x - lat_y)) * 6371.0
4.92535867182
关于mongodb - 使用 MongoDB 计算错误的距离,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19496883/