首页 > 其他 > 详细

地图上计算两点间的距离.(参考网络)

时间:2020-10-19 21:39:22      阅读:31      评论:0      收藏:0      [点我收藏+]
    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;

 

地图上计算两点间的距离.(参考网络)

原文:https://www.cnblogs.com/dygood/p/13841105.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!