GeoCoordinate.GetDistanceTo()
находится в System.Device.Location
пространства имен. Но приложения Windows 8.1 (приложения Runtime) используют Windows.Devices.Geolocation
пространство имен, где GetDistanceTo()
метода нет.
Вы можете сами рассчитать дистанцию с помощью формулы Haversine. Вот wikipedia Haversine page, вы можете узнать о формуле оттуда.
Вы можете использовать приведенный ниже код C#, который использует формулу Хаверсина для расчета расстояния между двумя координатами.
using System;
namespace HaversineFormula
{
/// <summary>
/// The distance type to return the results in.
/// </summary>
public enum DistanceType { Miles, Kilometers };
/// <summary>
/// Specifies a Latitude/Longitude point.
/// </summary>
public struct Position
{
public double Latitude;
public double Longitude;
}
class Haversine
{
/// <summary>
/// Returns the distance in miles or kilometers of any two
/// latitude/longitude points.
/// </summary>
public double Distance(Position pos1, Position pos2, DistanceType type)
{
double R = (type == DistanceType.Miles) ? 3960 : 6371;
double dLat = this.toRadian(pos2.Latitude - pos1.Latitude);
double dLon = this.toRadian(pos2.Longitude - pos1.Longitude);
double a = Math.Sin(dLat/2) * Math.Sin(dLat/2) +
Math.Cos(this.toRadian(pos1.Latitude)) * Math.Cos(this.toRadian(pos2.Latitude)) *
Math.Sin(dLon/2) * Math.Sin(dLon/2);
double c = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a)));
double d = R * c;
return d;
}
/// <summary>
/// Convert to Radians.
/// </summary>
private double toRadian(double val)
{
return (Math.PI/180) * val;
}
}