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

后端 未结 10 1593
死守一世寂寞
死守一世寂寞 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:17

    The bearing calculation is incorrect, you need to swap the inputs to atan2.

        bearing = atan2(sin(long2-long1)*cos(lat2), cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(long2-long1))
        bearing = degrees(bearing)
        bearing = (bearing + 360) % 360
    

    This will give you the correct bearing.

提交回复
热议问题