Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #a function that calculates straight line distance in meters between two points given latlng coordinates
- def haversine_distance(latlng1, latlng2):
- import math
- lat1 = float(latlng1[0])
- lng1 = float(latlng1[1])
- lat2 = latlng2[0]
- lng2 = latlng2[1]
- p = math.pi/180
- A = 0.5 - math.cos((lat2-lat1) * p)/2 + math.cos(lat1 * p) * math.cos(lat2 * p) * (1-math.cos((lng2- lng1) * p))/2
- distance = 12742 * math.asin((math.sqrt(A))) *1000 #in meter
- return round(distance,2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement