コード例 #1
0
        /// <summary>
        /// WGS-84转换GCJ-02
        /// </summary>
        /// <param name="wgLat">纬度</param>
        /// <param name="wgLon">经度</param>
        /// <returns></returns>
        public static GPSPoint WGS84_to_GCJ02(double wgLat, double wgLon)
        {
            GPSPoint point = new GPSPoint();

            if (OutOfChina(wgLat, wgLon))
            {
                point.SetLat(wgLat);
                point.SetLng(wgLon);
                return(point);
            }
            double dLat   = TransformLat(wgLon - 105.0, wgLat - 35.0);
            double dLon   = TransformLon(wgLon - 105.0, wgLat - 35.0);
            double radLat = wgLat / 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);
            dLon = (dLon * 180.0) / (a / sqrtMagic * Math.Cos(radLat) * pi);
            double lat = wgLat + dLat;
            double lon = wgLon + dLon;

            point.SetLat(lat);
            point.SetLng(lon);
            return(point);
        }
コード例 #2
0
        /// <summary>
        /// BD-09转换GCJ-02
        /// </summary>
        /// <param name="bd_lat">纬度</param>
        /// <param name="bd_lon">经度</param>
        /// <returns></returns>
        public static GPSPoint BD09_to_GCJ02(double bd_lat, double bd_lon)
        {
            GPSPoint point = new GPSPoint();
            double   x = bd_lon - 0.0065, y = bd_lat - 0.006;
            double   z      = Math.Sqrt(x * x + y * y) - 0.00002 * Math.Sin(y * x_pi);
            double   theta  = Math.Atan2(y, x) - 0.000003 * Math.Cos(x * x_pi);
            double   gg_lon = z * Math.Cos(theta);
            double   gg_lat = z * Math.Sin(theta);

            point.SetLat(gg_lat);
            point.SetLng(gg_lon);
            return(point);
        }
コード例 #3
0
        /// <summary>
        /// GCJ-02转换BD-09
        /// </summary>
        /// <param name="gg_lat">纬度</param>
        /// <param name="gg_lon">经度</param>
        /// <returns></returns>
        public static GPSPoint GCJ02_to_BD09(double gg_lat, double gg_lon)
        {
            GPSPoint point = new GPSPoint();
            double   x = gg_lon, y = gg_lat;
            double   z      = Math.Sqrt(x * x + y * y) + 0.00002 * Math.Sin(y * x_pi);
            double   theta  = Math.Atan2(y, x) + 0.000003 * Math.Cos(x * x_pi);
            double   bd_lon = z * Math.Cos(theta) + 0.0065;
            double   bd_lat = z * Math.Sin(theta) + 0.006;

            point.SetLat(bd_lat);
            point.SetLng(bd_lon);
            return(point);
        }