火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法(android)

    final double x_pi = 3.14159265358979324 * 3000.0 / 180.0;

    public GeoPoint bd_encrypt(GeoPoint point){

        double x = point.getLongitudeE6()/1E6;

        double y = point.getLatitudeE6()/1E6;

        

        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);

        

        GeoPoint bd_point = new GeoPoint((int) ((z*Math.sin(theta)+0.006)*1E6), (int) ((z*Math.cos(theta)+0.0065)*1E6));

        return bd_point;

    }

    

    public GeoPoint bd_decrypt(GeoPoint bd_point){

        double x = (double)bd_point.getLongitudeE6()/1E6 - 0.0065;

        double y = (double)bd_point.getLatitudeE6()/1E6 - 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);

        GeoPoint point = new GeoPoint((int)(z*Math.sin(theta)*1E6), (int)(z*Math.cos(theta)*1E6));

        return point;

    }

 

你可能感兴趣的:(android)