地图坐标转换

public class MapGCJToBUtill {

// 将 GCJ-02 坐标转换成 BD-09 坐标
public static GeoPoint bd_decrypt_geo(GeoPoint retGeoPt) {

double x_pi = 3.14159265358979324 * 3000.0 / 180.0;

double bd_lat = retGeoPt.getLatitudeE6() / 1000000.0;
double bd_lon = retGeoPt.getLongitudeE6() / 1000000.0;

double gg_lat = 0;
double gg_lon = 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_lat = z * Math.sin(theta);
gg_lon = z * Math.cos(theta);

GeoPoint r = new GeoPoint((int) (gg_lat * 100000),
(int) (gg_lon * 100000));

return r;
}

// 将 GCJ-02 坐标转换成 BD-09 坐标
public static GeoPoint bd_decrypt(int lat, int lon) {

double x_pi = 3.14159265358979324 * 3000.0 / 180.0;

double bd_lat = lat / 1000000.0;
double bd_lon = lon / 1000000.0;

double gg_lat = 0;
double gg_lon = 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_lat = z * Math.sin(theta);
gg_lon = z * Math.cos(theta);

GeoPoint r = new GeoPoint((int) (gg_lat * 100000),
(int) (gg_lon * 100000));

return r;
}

// 将 GCJ-02 坐标转换成 BD-09 坐标
public static GeoPoint bd_decrypt(double bd_lat, double bd_lon) {

double x_pi = 3.14159265358979324 * 3000.0 / 180.0;

double gg_lat = 0;
double gg_lon = 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_lat = z * Math.sin(theta);
gg_lon = z * Math.cos(theta);

GeoPoint r = new GeoPoint((int) (gg_lat * 100000),
(int) (gg_lon * 100000));

return r;
}

// 将 BD-09 坐标转换成 GCJ-02 坐标
public static GeoPoint bd_encrypt(GeoPoint retGeoPt) {
double x_pi = 3.14159265358979324 * 3000.0 / 180.0;

double gg_lat = retGeoPt.getLatitudeE6();
double gg_lon = retGeoPt.getLongitudeE6();

double bd_lat = 0;
double bd_lon = 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;

GeoPoint r = new GeoPoint((int) (bd_lat * 100000),
(int) (bd_lon * 100000));

return r;
}

}

转载自:https://blog.csdn.net/u010792039/article/details/44409685

You may also like...