Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivelant of .NET GeoCoordinate.GetDistanceTo in Windows 8 Metro style Apps

What is the equivelant of the System.Device.Location.GeoCoordinate.GetDistanceTo method in Metro style Windows 8 Applications.

Metro applications have the Geocoordinate class (With a lower case 'C') but no GetDistanceTo method.

Secondly, the Metro Geocoordinate class has no constructor. How can I create an instance of it.

like image 610
Muhammad Rehan Saeed Avatar asked Nov 28 '22 11:11

Muhammad Rehan Saeed


2 Answers

I decompiled the .NET 4.5 GetDistanceTo method as per BlackLight. Copying here to save people some effort.

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;
    }
}
like image 197
Sean Turner Avatar answered Nov 29 '22 23:11

Sean Turner


The Metro Geocoordinate has no public constructor for some reason. The best way to implement this in my opinion is to use Reflector and copy the implementation of System.Device.Location.GeoCoordinate which will also give you GetDistanceTo.

Hopefully this will be re-added to the API at a later time.

like image 29
BlackLight Avatar answered Nov 30 '22 01:11

BlackLight