在Windows 8 Metro风格的应用程序中使用.NET GeoCoordinate.GetDistanceTo等效

Muh*_*eed 4 .net c# getdistance microsoft-metro windows-8

Metro风格Windows 8应用程序中System.Device.Location.GeoCoordinate.GetDistanceTo方法的等效项是什么.

Metro应用程序具有Geocoordinate类(使用小写"C")但没有GetDistanceTo方法.

其次,Metro Geocoordinate类没有构造函数.我该如何创建它的实例.

Sea*_*ner 23

我根据BlackLight反编译了.NET 4.5 GetDistanceTo方法.在这里复制以节省一些人的努力.

public double GetDistanceTo(GeoCoordinate other)
{
    if (double.IsNaN(this.Latitude) || double.IsNaN(this.Longitude) || double.IsNaN(other.Latitude) || double.IsNaN(other.Longitude))
    {
        throw new ArgumentException(SR.GetString("Argument_LatitudeOrLongitudeIsNotANumber"));
    }
    else
    {
        double latitude = this.Latitude * 0.0174532925199433;
        double longitude = this.Longitude * 0.0174532925199433;
        double num = other.Latitude * 0.0174532925199433;
        double longitude1 = other.Longitude * 0.0174532925199433;
        double num1 = longitude1 - longitude;
        double num2 = num - latitude;
        double num3 = Math.Pow(Math.Sin(num2 / 2), 2) + Math.Cos(latitude) * Math.Cos(num) * Math.Pow(Math.Sin(num1 / 2), 2);
        double num4 = 2 * Math.Atan2(Math.Sqrt(num3), Math.Sqrt(1 - num3));
        double num5 = 6376500 * num4;
        return num5;
    }
}
Run Code Online (Sandbox Code Playgroud)