/*
* describe:地图坐标相互转换
* author:yvan
* 【note:百度地图采用的地图协议百度坐标系 (BD-09)
* 高德地图采用协议火星坐标系 (GCJ-02)】
* */
public class GCJ02_TO_BD09 {
double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
// bd_encrypt 将 BD-09坐标转换成 GCJ-02坐标
public void bd_decrypt(double bd_lat, double bd_lon )
{
double gg_lat; double gg_lon;
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);
System.out.println(gg_lon);
System.out.println(gg_lat);
}
// bd_encrypt 将 GCJ-02 坐标转换成 BD-09 坐标
public void bd_encrypt(double gg_lat, double gg_lon, double bd_lat, double bd_lon)
{
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;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
GCJ02_TO_BD09 gb=new GCJ02_TO_BD09();
gb.bd_decrypt(106.855615,26.243968);
}
}
* describe:地图坐标相互转换
* author:yvan
* 【note:百度地图采用的地图协议百度坐标系 (BD-09)
* 高德地图采用协议火星坐标系 (GCJ-02)】
* */
public class GCJ02_TO_BD09 {
double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
// bd_encrypt 将 BD-09坐标转换成 GCJ-02坐标
public void bd_decrypt(double bd_lat, double bd_lon )
{
double gg_lat; double gg_lon;
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);
System.out.println(gg_lon);
System.out.println(gg_lat);
}
// bd_encrypt 将 GCJ-02 坐标转换成 BD-09 坐标
public void bd_encrypt(double gg_lat, double gg_lon, double bd_lat, double bd_lon)
{
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;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
GCJ02_TO_BD09 gb=new GCJ02_TO_BD09();
gb.bd_decrypt(106.855615,26.243968);
}
}