Last active
February 16, 2016 18:14
-
-
Save aluminiumgeek/01d9195798c2ad9e7cb0 to your computer and use it in GitHub Desktop.
Calculate distance between two coordinates (latitude/longitude) in meters
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 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