cuốn sách gpt4 ai đã làm

mongodb - MongoDB 的错误距离计算

In lại Tác giả: Hồ Xil 更新时间:2023-11-01 09:12:28 26 4
mua khóa gpt4 Nike

我正在使用 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 公里。

khi tôi sử dụng Google Maps 计算这两个地理位置的距离时(比如开车去)它告诉我它们之间只有 5.2 公里。

我用不同位置的负载测试了它,google和Mongodb的距离计算总是有很大的差异

我是否遗漏了什么或者有人可以解释这种差异的来源吗?

我已经查过了câu trả lời này但它对我不起作用......

câu trả lời hay nhất

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/

26 4 0
Bài viết khuyến nghị: android - google-tv 模拟器似乎启动了,但随后什么也没做
Bài viết khuyến nghị: mongodb - 没有可用的隐式 View
Bài viết khuyến nghị: 安卓 HTTP 认证
Bài viết khuyến nghị: python - Pymongo 在子文档中通过 _id 查找
Hồ Xil
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress