Abid Hussain
Abid Hussain

Reputation: 102

How can I find the nearest point of intrest to my current location with the Windows Phone Map control?

I need to find out nearest location (in this case doctor's offices) from user current location using using Map control on windows phone 8.1.

I have my locations available in and XML file (latitude, longitude).

Is there a function that can return to me the distance to all of the points in my XML file?

Is there a way I can run that function asynchronously or in the background?

Is there a way I can animate the pin on the map (e.g., make it appear to jump)?

Upvotes: 1

Views: 417

Answers (1)

Depechie
Depechie

Reputation: 6142

To calculate the distance, I always use following Extension method on the BasicGeoposition class. To do this in the background, use a Task.Run(() => ).

public static double GetDistanceTo(this BasicGeoposition from, double toLatitude, double toLongitude)
{
    if (double.IsNaN(from.Latitude) || double.IsNaN(from.Longitude))
    {
        throw new ArgumentException("On of the given Latitude or Longitudes is not correct");
    }
    else
    {
        double latitude = from.Latitude * 0.0174532925199433;
        double longitude = from.Longitude * 0.0174532925199433;
        double num = toLatitude * 0.0174532925199433;
        double longitude1 = toLongitude * 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;
    }            
}

Upvotes: 1

Related Questions