C# 计算二个经纬度之间的距离

 

        static void Main(string[] args)
        {

            LatLng start = new LatLng(113.731389, 23.017926);
            LatLng end = new LatLng(113.723492, 23.032777);

            double lat1 = (Math.PI / 180) * start.latitude;
            double lat2 = (Math.PI / 180) * end.latitude;

            double lon1 = (Math.PI / 180) * start.longitude;
            double lon2 = (Math.PI / 180) * end.longitude;

            double r = 6371000; //地球半径(米)

            double d = Math.Acos(Math.Sin(lat1) * Math.Sin(lat2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Cos(lon2 - lon1)) * r;

            Console.WriteLine(d.ToString());

            Console.Read();

        }

        public class LatLng
        {
            public LatLng(double x, double y)
            {
                latitude = x;
                longitude = y;
            }
            public double latitude;
            public double longitude;
        }

 

posted on 2014-01-16 00:20  EasyBI  阅读(767)  评论(0)    收藏  举报

导航