Created
May 31, 2013 01:23
-
-
Save dansku/5682433 to your computer and use it in GitHub Desktop.
Measuring distance from two Geo-Points in Python
This file contains 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
import math | |
def distance(lat1, long1, lat2, long2): | |
R = 6371 # Earth Radius in Km | |
dLat = math.radians(lat2 - lat1) # Convert Degrees 2 Radians | |
dLong = math.radians(long2 - long1) | |
lat1 = math.radians(lat1) | |
lat2 = math.radians(lat2) | |
a = math.sin(dLat/2) * math.sin(dLat/2) + math.sin(dLong/2) * math.sin(dLong/2) * math.cos(lat1) * math.cos(lat2) | |
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) | |
d = R * c | |
return d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment