百度地圖的坐標轉換,由於百度地圖在GCJ02協議的基礎上又做了一次處理,變為 BD09協議的坐標,以下是坐標的轉化方式,可以方便和其他平台轉化
private const double x_pi = 3.14159265358979324 * 3000.0 / 180.0; /// <summary> /// 中國正常坐標系GCJ02協議的坐標,轉到 百度地圖對應的 BD09 協議坐標 /// </summary> /// <param name="lat">維度</param> /// <param name="lng">經度</param> public static void Convert_GCJ02_To_BD09(ref double lat,ref double lng) { double x = lng, y = 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); lng = z * Math.Cos(theta) + 0.0065; lat = z * Math.Sin(theta) + 0.006; } /// <summary> /// 百度地圖對應的 BD09 協議坐標,轉到 中國正常坐標系GCJ02協議的坐標 /// </summary> /// <param name="lat">維度</param> /// <param name="lng">經度</param> public static void Convert_BD09_To_GCJ02(ref double lat, ref double lng) { double x = lng - 0.0065, y = 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); lng = z * Math.Cos(theta); lat = z * Math.Sin(theta); }