JZLocationConverter-for-Android icon indicating copy to clipboard operation
JZLocationConverter-for-Android copied to clipboard

bd09 pertinent coordinate conversion error

Open Kerence opened this issue 8 years ago • 0 comments

bd09 pertinent coordinate convert with unacceptable error on account of an argument fault. algorithm should use following param X_PI as follows instead of Math.PI in JAVA static final double X_PI = 3.14159265358979324 * 3000.0 / 180.0; and replace Math.PI with X_PI ,the following code fixes error issue:

public static LatLng bd09Decrypt(double bdLat, double bdLon) {
    LatLng gcjPt = new LatLng();
    double x = bdLon - 0.0065, y = bdLat - 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);
    gcjPt.longitude = z * Math.cos(theta);
    gcjPt.latitude = z * Math.sin(theta);
    return gcjPt;
}

public static LatLng bd09Encrypt(double ggLat, double ggLon) {
    LatLng bdPt = new LatLng();
    double x = ggLon, y = ggLat;
    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);
    bdPt.longitude = z * Math.cos(theta) + 0.0065;
    bdPt.latitude = z * Math.sin(theta) + 0.006;
    return bdPt;
}

Kerence avatar Mar 13 '16 09:03 Kerence