两个经纬度之间的距离,lon点 [英] Distance between two lat,lon points

查看:354
本文介绍了两个经纬度之间的距离,lon点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以以经典的方式比较距离(2点之间的距离: d = sqrt(pow(lat2-lat1,2)+ pow(lon2-lon1,2)))使用从google apis返回的经纬度,而不用转换为米或者......?我只是为了比较才找到从一系列点到参考点的最近点。例如:

假设我们有两个(lat,lon)分数:(40.2535425,22.88245345)和(40.2565795,22.8884539)
,我们希望找到女巫最接近(40.2335425,22.83245345)。可以使用上面的代码来找到距离吗?或者我们需要找到距离,让我们以米为单位(使用半胱氨酸公式或任何其他方法),首先从参考点的每个点,然后比较值?

我问这个问题,因为我不知道google apis返回的值究竟是lat,lon!我的意思是说,他们不是度数?



谢谢...

解决方案

不,因为经度线会聚于两极。如果你的积分相对较近,那么可以近似这样的距离:
$ b $ pre code d = sqrt(pow(lat2-lat1,2) )+ cos(lat1)* pow(lon2-lon1,2))

如果您需要更高的准确度在很远的距离上,有几种奇特的公式用于计算大圆距离,但我发现在单位圆上转换成三维坐标变得更简单,然后做一个简单的毕达哥拉斯距离,接着2 sin(-1)( d / 2)转换回角度(尽管我可以理解有些人可能会发现 找不到这个简单的,: - )。


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...

解决方案

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, :-).

这篇关于两个经纬度之间的距离,lon点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆