Skip to content

Instantly share code, notes, and snippets.

@ilkermanap
Last active January 19, 2019 22:09
Show Gist options
  • Save ilkermanap/d6f077774ae4b934eed5871043aca0a9 to your computer and use it in GitHub Desktop.
Save ilkermanap/d6f077774ae4b934eed5871043aca0a9 to your computer and use it in GitHub Desktop.
Distance between two points with earth curve
def distance(lt1,ln1, lt2,ln2, in_meters = True):
"""
distance between two coordinates in meters
or in
"""
R = 6371000 # earth radius
theta1 = lt1 * PI / 180
theta2 = lt2 * PI / 180
delta_theta = (lt2 -lt1) * PI / 180
delta_fi = (ln2 - ln1) * PI / 180
a = (sin(delta_theta/2.0) ** 2) + (cos(theta1) * cos(theta2) *(sin(delta_fi/2.0) **2 ))
c = 2* atan2(sqrt(a), sqrt(1-a))
if in_meters:
return R * c
return c
@ilkermanap
Copy link
Author

forgot to add return in radian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment