Calculating the distance between 2 points in c#

后端 未结 4 1794
借酒劲吻你
借酒劲吻你 2020-12-18 04:41

I am trying to sort out a method to calculate the distance between 2 points in c#.

This is the code I have been trying though I fear the answer I get is not correct.

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-18 04:58

    The class I usually use is GeoCoordinate

    double latA = -31.997976f;
    double longA = 115.762877f;
    double latB = -31.99212f;
    double longB = 115.763228f;
    
    var locA = new GeoCoordinate(latA, longA);
    var locB = new GeoCoordinate(latB, longB);
    double distance = locA.GetDistanceTo(locB ); // metres
    

提交回复
热议问题