Ejemplo n.º 1
0
 /// <summary>
 /// 计算两个经纬度之间的直接距离
 /// </summary>
 public static double GetDistance(Geography start, Geography end)
 {
     double s = Math.Acos(Math.Cos(start.LatRadians) * Math.Cos(end.LatRadians) * Math.Cos(start.LngRadians - end.LngRadians) + Math.Sin(start.LatRadians) * Math.Sin(end.LatRadians));
     if (double.IsNaN(s)) return 0;
     s = s * EARTH_RADIUS;
     s = Math.Round(s * 10000) / 10000;
     return s;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 计算两个经纬度之间的直接距离
        /// </summary>
        public static double GetDistance(Geography start, Geography end)
        {
            double s = Math.Acos(Math.Cos(start.LatRadians) * Math.Cos(end.LatRadians) * Math.Cos(start.LngRadians - end.LngRadians) + Math.Sin(start.LatRadians) * Math.Sin(end.LatRadians));

            if (double.IsNaN(s))
            {
                return(0);
            }
            s = s * EARTH_RADIUS;
            s = Math.Round(s * 10000) / 10000;
            return(s);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 以一个经纬度为中心计算出四个顶点
 /// </summary>
 /// <param name="point">半径(米)</param>
 /// <param name="distance">半径(米)</param>
 /// <returns></returns>
 public static Range GetCoordinates(Geography point, double distance)
 {
     double dlng = Math.Abs(ToDegrees(2 * Math.Asin(Math.Sin(distance / (2 * EARTH_RADIUS)) / Math.Cos(point.Latitude))));
     double dlat = Math.Abs(ToDegrees(distance / EARTH_RADIUS));
     return new Range
     {
         Left = Math.Round(point.Longitude - dlng, 6),
         Right = Math.Round(point.Longitude + dlng, 6),
         Top = Math.Round(point.Latitude + dlat, 6),
         Bottom = Math.Round(point.Latitude - dlat, 6)
     };
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 以一个经纬度为中心计算出四个顶点
        /// </summary>
        /// <param name="point">半径(米)</param>
        /// <param name="distance">半径(米)</param>
        /// <returns></returns>
        public static Range GetCoordinates(Geography point, double distance)
        {
            double dlng = Math.Abs(ToDegrees(2 * Math.Asin(Math.Sin(distance / (2 * EARTH_RADIUS)) / Math.Cos(point.Latitude))));
            double dlat = Math.Abs(ToDegrees(distance / EARTH_RADIUS));

            return(new Range
            {
                Left = Math.Round(point.Longitude - dlng, 6),
                Right = Math.Round(point.Longitude + dlng, 6),
                Top = Math.Round(point.Latitude + dlat, 6),
                Bottom = Math.Round(point.Latitude - dlat, 6)
            });
        }