working out distances between two points using google maps api?

后端 未结 8 1328
北海茫月
北海茫月 2021-01-03 10:39

Is it possible to send two lat long points to google to calculate the distance between the two?

8条回答
  •  时光说笑
    2021-01-03 11:20

    And the distance cal in c#:

    // this returns the distance in miles. for km multiply result: * 1.609344
    public static double CalculateDistance(double lat1, double lon1, double lat2, double lon2)
    {
        double t = lon1 - lon2;
        double distance = Math.Sin(Degree2Radius(lat1)) * Math.Sin(Degree2Radius(lat2)) + Math.Cos(Degree2Radius(lat1)) * Math.Cos(Degree2Radius(lat2)) * Math.Cos(Degree2Radius(t));
        distance = Math.Acos(distance);
        distance = Radius2Degree(distance);
        distance = distance * 60 * 1.1515;
    
        return distance;
    }
    
    private static double Degree2Radius(double deg)
    {
        return (deg * Math.PI / 180.0);
    }
    
    private static double Radius2Degree(double rad)
    {
        return rad / Math.PI * 180.0;
    }
    

提交回复
热议问题