Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #a function that calculates straight line distance in meters between two points given latlng coordinates
  2. def haversine_distance(latlng1, latlng2):
  3. import math
  4. lat1 = float(latlng1[0])
  5. lng1 = float(latlng1[1])
  6. lat2 = latlng2[0]
  7. lng2 = latlng2[1]
  8.  
  9. p = math.pi/180
  10. A = 0.5 - math.cos((lat2-lat1) * p)/2 + math.cos(lat1 * p) * math.cos(lat2 * p) * (1-math.cos((lng2- lng1) * p))/2
  11. distance = 12742 * math.asin((math.sqrt(A))) *1000 #in meter
  12. return round(distance,2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement