Calculate distance between 2 GPS coordinates

前端 未结 29 4240
青春惊慌失措
青春惊慌失措 2020-11-21 23:34

How do I calculate distance between two GPS coordinates (using latitude and longitude)?

29条回答
  •  清歌不尽
    2020-11-22 00:05

    Here it is in C# (lat and long in radians):

    double CalculateGreatCircleDistance(double lat1, double long1, double lat2, double long2, double radius)
    {
        return radius * Math.Acos(
            Math.Sin(lat1) * Math.Sin(lat2)
            + Math.Cos(lat1) * Math.Cos(lat2) * Math.Cos(long2 - long1));
    }
    

    If your lat and long are in degrees then divide by 180/PI to convert to radians.

提交回复
热议问题