下面是百度官方对百度坐标为何有偏移的解释:国际经纬度坐标标准为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