两个纬度、经度点之间的距离

发布于 2024-10-29 04:08:25 字数 327 浏览 1 评论 0原文

使用纬度和从谷歌API返回的经度没有任何转换为​​米或某物?我需要它只是为了比较以找到一系列点到参考点的最近点。例如:

假设我们有两个(纬度,经度)点:(40.2535425,22.88245345)和(40.2565795,22.8884539) 我们想要找到最接近 (40.2335425,22.83245345) 的女巫。应用上面的代码可以找到距离吗?或者我们需要首先找到距参考点的每个点的距离,比如说以米为单位(使用半正矢公式或其他公式),然后比较这些值?

我问这个问题是因为我不知道 google apis 返回的值到底是什么,如经纬度!我的意思是它们不是度分秒,是吗?

谢谢...

Is it ok to compare distances in a classic way (distance between 2 points: d = sqrt(pow(lat2-lat1, 2) + pow(lon2-lon1, 2)) ) using the latitude and longitude returned from google apis without any transformation to meters or sth? I need it just for a comparison to find the closest point from a series of points to a reference point. For example:

Lets say we have two (lat,lon) points: (40.2535425,22.88245345) and (40.2565795,22.8884539)
and we want to find witch is closest to (40.2335425,22.83245345). Is it ok to apply the above code to find the distances? Or we need to find the distance, lets say in meters (using the haversine formula or whatever), first for each point from the reference point and then compare the values ?

I ask this question because I don't know what exactly are the values returned by google apis as lat, lon! I mean the are not deg-min-sec are they ?

Thanks...

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

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

发布评论

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

评论(2

╭⌒浅淡时光〆 2024-11-05 04:08:33

您还可以使用 computeDistanceBetween()我认为新的几何库返回以米为单位的距离

You can also use the computeDistanceBetween() from the new Geometry Library which i think returns the distance in meters

╰沐子 2024-11-05 04:08:29

不,因为经线向两极汇聚。如果您的点相对较近,您可以这样近似距离:

d = sqrt(pow(lat2-lat1, 2) + cos(lat1)*pow(lon2-lon1, 2))

如果您需要在长距离上获得更高的精度,有几个奇特的计算公式大圆距离,但我发现转换为单位圆上的 3D 坐标然后执行简单的毕达哥拉斯距离,然后是 2 sin-1(d/2) 转换回角度(尽管我可以理解,有些人可能会发现觉得这更简单,:-)。

No, because lines of longitude converge towards the poles. If your points are relatively close together, you can approximate the distance thus:

d = sqrt(pow(lat2-lat1, 2) + cos(lat1)*pow(lon2-lon1, 2))

If you need greater accuracy over large distances, there are several fancy formulae for computing great-circle distances, but I find it simpler to convert to 3D coordinates on a unit circle then do a simple pythagorean distance, followed by 2 sin-1(d/2) to convert back to an angle (though I can understand that some might find not find this simpler, :-).

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