根据地图上的两点坐标,计算直线距离

  /// <summary>
        /// 根据地图上的两点坐标,计算直线距离
        /// </summary>
        /// <param name="sLat">起点纬度</param>
        /// <param name="sLng">起点经度</param>
        /// <param name="eLat">终点纬度</param>
        /// <param name="eLng">终点经度</param>
        /// <returns>返回两点间的直线距离</returns>
        private static double GetRealDistance(double sLat, double sLng, double eLat, double eLng)
        {
            //javascript======round(6378.138*2*asin(sqrt(pow(sin(( $p1_x *pi()/180-$p2_x*pi()/180)/2),2)+cos( $p1_x *pi()/180)*cos($p2_x*pi()/180)* pow(sin(( $p1_y *pi()/180-$p2_y*pi()/180)/2),2)))*1000);

            //转成千米
            double distance = Math.Round(
                6378.138 * 2 * Math.Asin(
                    Math.Sqrt(
                        Math.Pow(Math.Sin((sLat * Math.PI / 180 - eLat * Math.PI / 180)) / 2, 2) +
                        Math.Cos(sLat * Math.PI / 180) * Math.Cos(eLat * Math.PI / 180) *
                        Math.Pow(Math.Sin((sLng * Math.PI / 180 - eLng * Math.PI / 180)) / 2, 2)
                    )
                ) * 1000
            );
            //如果 转成米  乘1000
            return distance;
        }
原文地址:https://www.cnblogs.com/xiaobing-R/p/13665245.html