SHARE
TWEET

Untitled

a guest Aug 20th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top