Skip to content

Instantly share code, notes, and snippets.

@blixt
Created December 1, 2015 17:03
Show Gist options
  • Save blixt/6bf80b659e62364fdbcf to your computer and use it in GitHub Desktop.
Save blixt/6bf80b659e62364fdbcf to your computer and use it in GitHub Desktop.
Distance between lat/lon geo point
def point_distance(a, b):
degrees_to_radians = math.pi / 180
phi_a = (90 - a.lat) * degrees_to_radians
phi_b = (90 - b.lat) * degrees_to_radians
theta_a = a.lon * degrees_to_radians
theta_b = b.lon * degrees_to_radians
cos = (math.sin(phi_a) * math.sin(phi_b) * math.cos(theta_a - theta_b) +
math.cos(phi_a) * math.cos(phi_b))
arc = math.acos(cos)
return arc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment