为我提供了属于空间参考 GCJ-02 的 LatLng。当然它不会在谷歌地图中正确显示,因为我相信,如果我错了,请纠正我,谷歌地图使用 WGS-84。
google map service v2 for android 是否提供了一种显示或转换 GCJ-02 的方法?
使用地理工具是我唯一的选择吗?我不想仅仅为了空间转换而引入如此庞大的图书馆。
谢谢你的帮助,凯夫
为我提供了属于空间参考 GCJ-02 的 LatLng。当然它不会在谷歌地图中正确显示,因为我相信,如果我错了,请纠正我,谷歌地图使用 WGS-84。
google map service v2 for android 是否提供了一种显示或转换 GCJ-02 的方法?
使用地理工具是我唯一的选择吗?我不想仅仅为了空间转换而引入如此庞大的图书馆。
谢谢你的帮助,凯夫
Around the time the question was asked, the only way to convert between GCJ-02 and WGS-84 was to use an interpolation method with coordinates based on regression from a data set of Google China and satellite imagery coordinates. There is an Objective-C library on GitHub at https://github.com/maxime/ChinaMapDeviation.
However, since the question was asked, the GCJ-02 encryption code was leaked and can be found in many places online, the most popular being the EvilTransform repo.
Further reading:
public static LatLng wgs_gcj_encrypts(double wgLat, double wgLon) {
LatLng point;
if (outOfChina(wgLat, wgLon)) {
Log.e("Baidu", "outOfChina");
point = new LatLng(wgLat,wgLon);
return point;
}
double dLat = transformLat(wgLon - 105.0, wgLat - 35.0);
double dLon = transformLon(wgLon - 105.0, wgLat - 35.0);
double radLat = wgLat / 180.0 * pi;
double magic = Math.sin(radLat);
magic = 1 - ee * magic * magic;
double sqrtMagic = Math.sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi);
double lat = wgLat + dLat;
double lon = wgLon + dLon;
point = new LatLng(lat,lon);
return point;
}
private static boolean outOfChina(double lat, double lon) {
if (lon < 72.004 || lon > 137.8347)
return true;
if (lat < 0.8293 || lat > 55.8271)
return true;
return false;
}
public static double transformLat(double x, double y) {
double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0;
return ret;
}
public static double transformLon(double x, double y) {
double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0;
return ret;
}
谷歌地图将接受 4326 但如果你真的想正确 - 阅读这篇文章
https://gis.stackexchange.com/questions/253/what-is-the-current-web-mercator-projection-code
您可以使用 proj4 或将数据存储在 PostGIS 中(它可以为您进行转换)。我不知道 android 客户端上的任何库可以做到这一点,但也许这对你来说可能是诀窍: