Created
January 15, 2018 20:24
-
-
Save adamb70/02666be9c22697c50685551975cc0d90 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def haversine(lat1, lon1, lat2, lon2, miles=False): | |
phi1, phi2, dlat, dlon = map(radians, [lat1, lat2, lat2-lat1, lon2-lon1]) | |
radius = 6371 | |
if miles: | |
radius = 3956 | |
a = sin(dlat/2)**2 + cos(phi1) * cos(phi2) * sin(dlon/2)**2 | |
c = 2 * asin(sqrt(a)) | |
return radius * c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adapted from https://www.movable-type.co.uk/scripts/latlong.html