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

What is the equivalent of the System.Device.Location.GeoCoordinate.GetDistanceTo method in Metro-style Windows 8 applications.

Metro applications have the Geocoordinate class (lowercase C), but not the GetDistanceTo method.

Secondly, the Metro Geocoordinate class does not have a constructor. How can I create an instance of it.

+4
source share
3 answers

Metro Geocoordinate does not have a public constructor by default. 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 .

We hope this will be added to the API later.

+2
source

I decompiled the .NET 4.5 GetDistanceTo method according to BlackLight. Copying is here to save people.

 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; } } 
+23
source

I wrote a small library for working with coordinates a year ago or something that can help you calculate the distances between coordinates. It is available at CodePlex: http://beavergeodesy.codeplex.com/

Then calculating the distances is as simple as that.

 // Create a pair of coordinates GeodeticCoordinate coordinate1 = new GeodeticCoordinate() { Latitude = 63.83451d, Longitude = 20.24655d }; GeodeticCoordinate coordinate2 = new GeodeticCoordinate() { Latitude = 63.85763d, Longitude = 20.33569d }; // Calculate the distance between the coordinates using the haversine formula double distance = DistanceCalculator.Haversine(coordinate1, coordinate2); 
+2
source

Source: https://habr.com/ru/post/1434458/


All Articles