Haversine Formula in Python (Bearing and Distance between two GPS points)

后端 未结 10 1762
死守一世寂寞
死守一世寂寞 2020-11-22 09:47

Problem

I would like to know how to get the distance and bearing between 2 GPS points. I have researched on the haversine formula. Someone told me

10条回答
  •  醉梦人生
    2020-11-22 10:18

    There is also a vectorized implementation, which allows to use 4 numpy arrays instead of scalar values for coordinates:

    def distance(s_lat, s_lng, e_lat, e_lng):
    
       # approximate radius of earth in km
       R = 6373.0
    
       s_lat = s_lat*np.pi/180.0                      
       s_lng = np.deg2rad(s_lng)     
       e_lat = np.deg2rad(e_lat)                       
       e_lng = np.deg2rad(e_lng)  
    
       d = np.sin((e_lat - s_lat)/2)**2 + np.cos(s_lat)*np.cos(e_lat) * np.sin((e_lng - s_lng)/2)**2
    
       return 2 * R * np.arcsin(np.sqrt(d))
    

提交回复
热议问题