Skip to content

Instantly share code, notes, and snippets.

@Naesstrom
Last active October 12, 2018 12:55
Show Gist options
  • Save Naesstrom/23185cb61407779db4007d979ca865a6 to your computer and use it in GitHub Desktop.
Save Naesstrom/23185cb61407779db4007d979ca865a6 to your computer and use it in GitHub Desktop.
from math import radians, sin, cos, acos
"""
slat = Start Latitude
slon = Start Longitude
elat = End Latitude
elon = End Longitude
"""
slon,slat = 16.596265846848024,62.811484968080336
elat,elon = 56.8734129,14.7967102
#Convert coordinates to radians
elat2 = radians(float(elat))
slat2 = radians(float(slat))
elon2 = radians(float(elon))
slon2 = radians(float(slon))
#Calculate the distance between them
dist = 6371.01 * acos(sin(slat2)*sin(elat2) + cos(slat2)*cos(elat2)*cos(slon2 - elon2))
print("The distance is %.2fkm." % dist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment