public struct Location
{
/// <summary>
/// 經度
/// </summary>
public double Longitude { get; set; }
/// <summary>
/// 緯度
/// </summary>
public double Latitude { get; set; }
}
/// <summary>
/// 地球半径,单位米
/// </summary>
private const double EARTH_RADIUS = 6371393.0d;
/// <summary>
/// 计算两点位置的距离,返回两点的距离,单位 米
/// 该公式为GOOGLE提供,误差小于0.2米
/// </summary>
/// <param name="first"></param>
/// <param name="second"></param>
/// <returns></returns>
private static double Distance(Location first, Location second)
{
var radLat1 = Rad(first.Latitude);
var radLng1 = Rad(first.Longitude);
var radLat2 = Rad(second.Latitude);
var radLng2 = Rad(second.Longitude);
var a = radLat1 - radLat2;
var b = radLng1 - radLng2;
return 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(a / 2), 2) + Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(b / 2), 2))) * EARTH_RADIUS;
}
/// <summary>
/// 经纬度转化成弧度
/// </summary>
/// <param name="d"></param>
/// <returns></returns>
private static double Rad(double d) => (double)d * Math.PI / 180d;