Created
December 1, 2015 17:03
-
-
Save blixt/6bf80b659e62364fdbcf to your computer and use it in GitHub Desktop.
Distance between lat/lon geo point
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 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