如何使用纬度和经度计算距离和方位?

发布于 2024-10-02 13:06:45 字数 468 浏览 0 评论 0原文

假设这 4 个值:

        double lat1 = ToRadians(53.14722222222222);
        double lon1 = ToRadians(-1.8494444444444447);
        double lat2 = ToRadians(52.20444444444445);
        double lon2 = ToRadians(-0.14055555555555554);

我在 Google 地图获取方向中计算,我得到了大约 181 公里,但在这个网站 (http://www.movable-type.co.uk/scripts/latlong.html) 中得到了大约 170 公里。

在我的源码中,我使用java和c#来实现这个功能,当我计算时,我得到了大约155公里。

为什么它们不等价?

有没有可以准确计算这两个值的函数?

Assume these 4 values:

        double lat1 = ToRadians(53.14722222222222);
        double lon1 = ToRadians(-1.8494444444444447);
        double lat2 = ToRadians(52.20444444444445);
        double lon2 = ToRadians(-0.14055555555555554);

I calculate in Google map get direction, I got about 181 km, but in this website (http://www.movable-type.co.uk/scripts/latlong.html) it got about 170 km.

In my source, I use java and c# to implement this function, when I calculate it, I got about 155 km.

why they are not equivalent?

Do you have any function that can calculate this 2 values accurately?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吹泡泡o 2024-10-09 13:06:45

网站上的半正矢公式“直线上升”,相当准确。你没有说你如何使用谷歌地图来计算距离,但如果你只是输入值并要求它计算路线,它会使用行驶距离(跟随道路),这会更长。如果您对半正矢公式的实现得出的答案与网站不同,那么您或他们的实现不正确。您可能会找到另一个网站来检查您的答案,看看是哪个。

您可以在 C# 中找到一个实现 这里

The Haversine formula on the web site is reasonable accurate "as the crow flies." You don't say how you used Google maps to calculate the distance, but if you simply put in the values and asked it to calculate a route, it would be using the driving distance (following roads) which would be longer. If your implementation of the Haversine formula comes up with a different answer than the web site, then either you or they have implemented it incorrectly. You might find another web site to check your answer against to see which.

You can find an implementation in C# here.

独﹏钓一江月 2024-10-09 13:06:45

在 Google 地球上该值为 155.92 公里。
所以它与你的结果一致。

Google 地球使用大圆距离计算,该计算考虑了地球是一个球体。
不过我不知道其他两个来源。

我会保留您当前的实施。

On Google Earth the value is 155.92km.
So it agrees with your result.

Google Earth uses a Great Circle Distance calculation, that takes into account the fact that the Earth is a Sphere.
I don't know about the other two sources though.

I would keep your current implementation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文