def get_crow_fly_distance(from_tuple, to_tuple):
"""
Uses the Haversine formmula to compute distance
(https://en.wikipedia.org/wiki/Haversine_formula#The_haversine_formula)
"""
lat1, lon1 = from_tuple
lat2, lon2 = to_tuple
lat1 = float(lat1)
lat2 = float(lat2)
lon1 = float(lon1)
lon2 = float(lon2)
radius = 6371 # km
dlat = math.radians(lat2 - lat1)
dlon = math.radians(lon2 - lon1)
a = math.sin(dlat / 2) * math.sin(dlat / 2) + math.cos(math.radians(lat1)) * \
math.cos(math.radians(lat2)) * math.sin(dlon / 2) * math.sin(dlon / 2)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
d = radius * c
return d * 1000 # meters
评论列表
文章目录