Skip to content

Instantly share code, notes, and snippets.

Created December 20, 2012 03:51
Show Gist options
  • Save anonymous/4342829 to your computer and use it in GitHub Desktop.
Save anonymous/4342829 to your computer and use it in GitHub Desktop.
Calculate the great circle distance between two points on the earth (specified in decimal degrees)
def haversine(site_one, site_2):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees)
"""
lat1 , lon1 = site_one
lat2 , lon2 = site_2
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
distance = acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon2-lon1))*6371
distance = distance * 1000
return distance
google = 37.422045, -122.084347
tower = 48.8582, 2.294407
opera = -33.856553, 151.214696
sf = 37.77493, -122.419416
print haversine(google,tower)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment