闲坐敲棋

有约不来过夜半,闲敲棋子落灯花

导航

c# 根据经纬度 求两点之间的距离

Posted on 2009-05-25 17:07  闲坐敲棋  阅读(318)  评论(0编辑  收藏  举报

public static double Fun_Rad(double d)
        {
            return d * Math.PI / 180.0;
        }

        public static double Fun_GetDistance(double lat1, double lng1, double lat2, double lng2)
        {
            double d_EarthRadius = 6378.137;
            double radLat1 = Fun_Rad(lat1);
            double radLat2 = Fun_Rad(lat2);
            double radLat = Fun_Rad(lat1) - Fun_Rad(lat2);
            double radLng = Fun_Rad(lng1) - Fun_Rad(lng2);
            double s = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(radLat / 2), 2) +
             Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(radLng / 2), 2)));
            s = s * d_EarthRadius;
            s = Math.Round(s * 10000) / 10000;
            return s;