Calculate distance of two geo points in km c#

前端 未结 7 680
夕颜
夕颜 2020-12-03 00:21

I`d like calculate the distance of two geo points. the points are given in longitude and latitude.

the coordinates are:

point 1: 36.578581, -118.291994

7条回答
  •  渐次进展
    2020-12-03 00:31

    As you are using the framework 4.0, I would suggest the GeoCoordinate class.

    // using System.Device.Location;
    
    GeoCoordinate c1 = new GeoCoordinate(36.578581, -118.291994);
    GeoCoordinate c2 = new GeoCoordinate(36.23998, -116.83171);
    
    double distanceInKm = c1.GetDistanceTo(c2) / 1000;
    // Your result is: 136,111419742602
    

    You have to add a reference to System.Device.dll.

提交回复
热议问题