Skip to content

Instantly share code, notes, and snippets.

@aialenti
Last active December 13, 2019 13:26
Show Gist options
  • Save aialenti/61dbd967b3f6dd362032a7775c6dd127 to your computer and use it in GitHub Desktop.
Save aialenti/61dbd967b3f6dd362032a7775c6dd127 to your computer and use it in GitHub Desktop.
def calculate_distance(self, lat_a, lng_a, lat_b, lng_b):
# Convert lat lng in radians
lng_a, lat_a, lng_b, lat_b = map(math.radians, [lng_a, lat_a, lng_b, lat_b])
d_lat = lat_b - lat_a
d_lng = lng_a - lng_b
temp = (
math.sin(d_lat / 2) ** 2
+ math.cos(lat_a)
* math.cos(lat_b)
* math.sin(d_lng / 2) ** 2
)
return 6373.0 * (2 * math.atan2(math.sqrt(temp), math.sqrt(1 - temp)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment