spyder中haversine函数怎么用
时间: 2023-04-02 14:04:07 浏览: 189
解决Spyder中图片显示太小的问题
可以使用以下代码调用spyder中的haversine函数:
```python
from math import radians, cos, sin, asin, sqrt
def haversine(lon1, lat1, lon2, lat2):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees)
"""
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
c = 2 * asin(sqrt(a))
r = 6371 # Radius of earth in kilometers. Use 3956 for miles
return c * r
```
其中,lon1、lat1、lon2、lat2分别代表两个经纬度点的经度和纬度,单位为度。函数返回值为这两个点之间的距离,单位为千米。
阅读全文