Ejemplo n.º 1
0
        /// <summary>
        /// GCJ02 转换为 WGS84
        /// </summary>
        /// <param name="lng">经度</param>
        /// <param name="lat">纬度</param>
        /// <returns></returns>
        public static GeoLatLng gcj02towgs84(double lng, double lat)
        {
            GeoLatLng wgs84Pt = new GeoLatLng(lat, lng);

            if (out_of_china(lng, lat))
            {
                return(wgs84Pt);
            }
            else
            {
                double dlat   = transformlat(lng - 105.0, lat - 35.0);
                double dlng   = transformlng(lng - 105.0, lat - 35.0);
                double radlat = lat / 180.0 * PI;
                double magic  = Math.Sin(radlat);
                magic = 1 - ee * magic * magic;
                double sqrtmagic = Math.Sqrt(magic);
                dlat = dlat * 180.0 / (a * (1 - ee) / (magic * sqrtmagic) * PI);
                dlng = dlng * 180.0 / (a / sqrtmagic * Math.Cos(radlat) * PI);
                double mglat = lat + dlat;
                double mglng = lng + dlng;
                wgs84Pt.longitude = lng * 2 - mglng;
                wgs84Pt.latitude  = lat * 2 - mglat;
                return(wgs84Pt);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 百度坐标转墨卡托
        /// </summary>
        /// <param name="p">百度坐标点</param>
        /// <returns></returns>
        public static MercatorPoint BDLatLng2Mercator(GeoLatLng p)
        {
            double[] arr   = null;
            double   n_lat = p.latitude > 74 ? 74 : p.latitude;

            n_lat = n_lat < -74 ? -74 : n_lat;
            for (var i = 0; i < array1.Length; i++)
            {
                if (p.latitude >= array1[i])
                {
                    arr = array2[i];
                    break;
                }
            }
            if (arr == null)
            {
                for (var i = array1.Length - 1; i >= 0; i--)
                {
                    if (p.latitude <= -array1[i])
                    {
                        arr = array2[i];
                        break;
                    }
                }
            }
            double[] res = BDConvertor(p.longitude, p.latitude, arr);
            return(new MercatorPoint((float)res[0], (float)res[1]));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 判断是否在国内
 /// </summary>
 /// <param name="location">坐标点</param>
 /// <returns></returns>
 public static bool out_of_china(GeoLatLng location)
 {
     if (location == null)
     {
         return(false);
     }
     return(out_of_china(location.longitude, location.latitude));
 }