Quicker way to calculate geographic distance between two points

后端 未结 4 1539
醉酒成梦
醉酒成梦 2020-12-05 08:37

I borrowed the following method from somewhere on the internet (Can\'t remember where). But its doing a straight forward process, finding the distance between two gps points

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 09:21

    You might try the law of cosines for spherical trigonometry:

    a = sin(lat1) * sin(lat2)
    b = cos(lat1) * cos(lat2) * cos(lon2 - lon1)
    c = arccos(a + b)
    d = R * c
    

    But it will be inaccurate for short distances (and probably just marginally faster).

    There is a complete discussion here. However, the haversine formula is the most correct way, so aside from what others have suggested there may not be much you can do. @Alnitak's answer may work, but spherical to Cartesian conversions are not necessarily fast.

提交回复
热议问题