Skip to content

Instantly share code, notes, and snippets.

@erickgnavar
Forked from anonymous/haversine.py
Created December 21, 2012 04:52
Show Gist options
  • Save erickgnavar/4350691 to your computer and use it in GitHub Desktop.
Save erickgnavar/4350691 to your computer and use it in GitHub Desktop.
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