Пример #1
0
        /// <summary>
        /// 将真实经纬度转国家加密经纬度
        /// </summary>
        /// <param name="wgLoc"></param>
        /// <returns></returns>
        public static TMapPoint transformFromWGSToGCJ(TMapPoint wgLoc)
        {
            TMapPoint mgLoc = null;

            if (outOfChina(wgLoc.GetLat, wgLoc.GetLng))
            {
                mgLoc = wgLoc;
                return(mgLoc);
            }
            else
            {
                mgLoc = new TMapPoint(0.00, 0.00);
            }
            double dLat   = transformLat(wgLoc.GetLng - 105.0, wgLoc.GetLat - 35.0);
            double dLon   = transformLon(wgLoc.GetLng - 105.0, wgLoc.GetLat - 35.0);
            double radLat = wgLoc.GetLat / 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);
            mgLoc.SetLat(wgLoc.GetLat + dLat);
            mgLoc.SetLng(wgLoc.GetLng + dLon);

            return(mgLoc);
        }
Пример #2
0
        /// <summary>
        /// 将百度经纬度转国家加密经纬度
        /// </summary>
        /// <param name="bdLoc"></param>
        /// <returns></returns>
        public static TMapPoint bd_decrypt(TMapPoint bdLoc)
        {
            double x     = bdLoc.GetLng - 0.0065;
            double y     = bdLoc.GetLat - 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);

            return(LocationMake(z * Math.Cos(theta), z * Math.Sin(theta)));
        }
Пример #3
0
        /// <summary>
        /// 将国家加密经纬度转百度经纬度
        /// </summary>
        /// <param name="gcLoc"></param>
        /// <returns></returns>
        public static TMapPoint bd_encrypt(TMapPoint gcLoc)
        {
            double x     = gcLoc.GetLng;
            double y     = gcLoc.GetLat;
            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);

            return(LocationMake(z * Math.Cos(theta) + 0.0065, z * Math.Sin(theta)
                                + 0.006));
        }
Пример #4
0
        /// <summary>
        /// 把真实转为百度经纬度
        /// </summary>
        /// <param name="lng"></param>
        /// <param name="lat"></param>
        /// <returns></returns>
        public static double[] TrueToBaidu(double lng, double lat)
        {
            double[] retu1 = new double[2];

            TMapPoint wgLoc = new TMapPoint(lng, lat);

            TMapPoint wgLocCountry = transformFromWGSToGCJ(wgLoc);

            TMapPoint wgLocBaidu = Revise_LatLonUtil.bd_encrypt(wgLocCountry);

            retu1[0] = wgLocBaidu.GetLng;
            retu1[1] = wgLocBaidu.GetLat;

            return(retu1);
        }
Пример #5
0
        /// <summary>
        /// 将国家加密经纬度转真实经纬度
        /// </summary>
        /// <param name="gcLoc"></param>
        /// <returns></returns>
        public static TMapPoint transformFromGCJToWGS(TMapPoint gcLoc)
        {
            TMapPoint wgLoc     = new TMapPoint(gcLoc.GetLng, gcLoc.GetLat);
            TMapPoint currGcLoc = null;
            TMapPoint dLoc      = new TMapPoint(0.00, 0.00);

            while (true)
            {
                currGcLoc = transformFromWGSToGCJ(wgLoc);
                dLoc.SetLat(gcLoc.GetLat - currGcLoc.GetLat);
                dLoc.SetLng(gcLoc.GetLng - currGcLoc.GetLng);
                if (Math.Abs(dLoc.GetLat) < 1e-7 && Math.Abs(dLoc.GetLat) < 1e-7)
                {
                    return(wgLoc);
                }
                wgLoc.SetLat(wgLoc.GetLat + dLoc.GetLat);
                wgLoc.SetLng(wgLoc.GetLng + dLoc.GetLng);
            }
        }