1 介绍
- Haversine距离用于计算地球上两点之间的大圆距离
- 当考虑地球的真实曲率时,它特别适用于计算两个经纬度坐标之间的距离
其中:
2 python 实现
python
def haversine_distance(lat1, lon1, lat2, lon2):
R = 6371 # Earth radius in kilometers
dlat = np.radians(lat2 - lat1)
dlon = np.radians(lon2 - lon1)
a = np.sin(dlat/2) * np.sin(dlat/2) + np.cos(np.radians(lat1)) * np.cos(np.radians(lat2)) * np.sin(dlon/2) * np.sin(dlon/2)
c = 2 * np.arctan2(np.sqrt(a), np.sqrt(1-a))
return R * c