百度坐标转火星坐标

时间:2015-04-23 15:47:21   收藏:0   阅读:217

下面是百度官方对百度坐标为何有偏移的解释:国际经纬度坐标标准为WGS-84,国内必须至少使用国测局制定的GCJ-02,对地理位置进行首次加密。百度坐标在此基础上,进行了BD-09二次加密措施,更加保护了个人隐私。 百度对外接口的坐标系并不是GPS采集的真实经纬度,需要通过坐标转换接口进行转换


        /// <summary>
        ///  GCJ-02(火星坐标) 坐标转换成 BD-09(百度坐标) 坐标
        /// </summary>
        /// <param name="gg_lon">火星经度</param>
        /// <param name="gg_lat">火星纬度</param>
        /// <param name="bd_lon">百度经度</param>
        /// <param name="bd_lat">百度纬度</param>
        public void bd_encrypt(double gg_lon, double gg_lat, ref double bd_lon, ref double bd_lat)
        {
            double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
            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);
            bd_lon = z * Math.Cos(theta) + 0.0065;//经度
            bd_lat = z * Math.Sin(theta) + 0.006;//纬度
        }

        /// <summary>
        ///  BD-09(百度坐标) 坐标转换成  GCJ-02(火星坐标) 坐标
        /// </summary>
        /// <param name="bd_lon">百度经度</param>
        /// <param name="bd_lat">百度纬度</param>
        /// <param name="gg_lon">火星经度</param>
        /// <param name="gg_lat">火星纬度</param>
        public void bd_decrypt(double bd_lon, double bd_lat, ref double gg_lon, ref double gg_lat)
        {
            double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
            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);
            gg_lon = z * Math.Cos(theta);//经度
            gg_lat = z * Math.Sin(theta);//纬度
        }


原文:http://blog.csdn.net/jayzai/article/details/45220947

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!