Created
June 8, 2013 07:21
-
-
Save KevinWG/5734398 to your computer and use it in GitHub Desktop.
百度地图的坐标转换,由于百度地图在GCJ02协议的基础上又做了一次处理,变为 BD09协议的坐标,以下是坐标的转化方式,可以方便和其他平台转化
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment