dygood
  • 经纬度结构体
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;

分类:

技术点:

相关文章:

  • 2021-11-27
  • 2021-11-27
  • 2021-06-27
  • 2022-01-01
  • 2022-01-23
  • 2022-12-23
  • 2021-11-27
猜你喜欢
  • 2022-02-09
  • 2021-12-13
  • 2021-11-27
  • 2021-11-19
  • 2021-11-27
  • 2021-05-28
相关资源
相似解决方案