Skip to content

Instantly share code, notes, and snippets.

@wlach
Created April 6, 2009 14:47
Show Gist options
  • Save wlach/90779 to your computer and use it in GitHub Desktop.
Save wlach/90779 to your computer and use it in GitHub Desktop.
def latlng_dist(src_lat, src_lng, dest_lat, dest_lng):
if src_lat == dest_lat and src_lng == dest_lng:
return 0.0
theta = float(src_lng) - float(dest_lng);
src_lat_radians = math.radians(float(src_lat));
dest_lat_radians = math.radians(float(dest_lat));
dist = math.sin(src_lat_radians) * math.sin(dest_lat_radians) + \
math.cos(src_lat_radians) * math.cos(dest_lat_radians) * \
math.cos(math.radians(theta));
dist = math.acos(dist);
dist = math.degrees(dist);
dist *= (60.0 * 1.1515 * 1.609344 * 1000.0);
return dist;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment