/// <summary> /// Computes the aproximate distance between to geographic points /// </summary> /// <returns>Distance in KM</returns> public static double DistanceFrom(GeoPoint from, GeoPoint to) { const int r = 6371; // Radius of the earth in km var a = 0.5 - Math.Cos((to.Latitude - from.Latitude) * Math.PI / 180) / 2 + Math.Cos(from.Latitude * Math.PI / 180) * Math.Cos(to.Latitude * Math.PI / 180) * (1 - Math.Cos((to.Longitude - from.Longitude) * Math.PI / 180)) / 2; return r * 2 * Math.Asin(Math.Sqrt(a)); }
/// <summary> /// Computes the aproximate distance between to geographic points /// </summary> /// <returns>Distance in KM</returns> public double DistanceFrom(GeoPoint destination) => DistanceFrom(this, destination);