Skip to content

Instantly share code, notes, and snippets.

@aluminiumgeek
Last active February 16, 2016 18:14
Show Gist options
  • Select an option

  • Save aluminiumgeek/01d9195798c2ad9e7cb0 to your computer and use it in GitHub Desktop.

Select an option

Save aluminiumgeek/01d9195798c2ad9e7cb0 to your computer and use it in GitHub Desktop.
Calculate distance between two coordinates (latitude/longitude) in meters
def coords_distance(coords_from, coords_to):
lat1, long1 = coords_from
lat2, long2 = coords_to
degrees_to_radians = math.pi / 180.0
phi1 = (90.0 - lat1) * degrees_to_radians
phi2 = (90.0 - lat2) * degrees_to_radians
theta1 = long1 * degrees_to_radians
theta2 = long2 * degrees_to_radians
cos = math.sin(phi1) * math.sin(phi2) * math.cos(theta1 - theta2) + math.cos(phi1) * math.cos(phi2)
arc = math.acos( cos )
meters = arc * 6373000
return meters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment