mongodb - MongoDB 的错误距离计算

标签 mongodb distance geospatial

我正在使用 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/

相关文章:

r - 如何将对称矩阵转换为 "dist"对象?

geospatial - GeoPandas:如何获取地理数据框中每个几何图形的边界框

html - IndexedDB 中的地理空间查询

mongodb - 如何在 Meteor 服务器端做 mongo 组

mongodb - Mongo导入错误: X509_STORE_add_cert:cert already in hash table

python - 将networkx图输入zss算法(树编辑距离)

MySQL空间查询总是为空

mongodb - 通过浏览器连接mongodb?

Mongodb聚合框架: Sum values for max date in month

r - 如何使用 R 选择/查找距离列表 (X/Y) 一定距离内的坐标