高德坐标转百度,百度转高德


/**
     * 高德转百度
     *
     * @param longitude 经度
     * @param latitude  纬度
     * @return [经度, 纬度]
     */
    public static double[] calGCJ02toBD09(double longitude, double latitude) {
        double z = Math.sqrt(longitude * longitude + latitude * latitude) + 0.00002 * Math.sin(latitude * PI);
        double theta = Math.atan2(latitude, longitude) + 0.000003 * Math.cos(longitude * PI);
        double retLat = z * Math.sin(theta) + 0.006;
        double retLon = z * Math.cos(theta) + 0.0065;
        return new double[]{retLon, retLat};
    }
    

    //百度转高德
    public static double[] bd09ToGcj02(double bd_lon,double bd_lat )

    {

        double x = bd_lon - 0.0065, y = bd_lat - 0.006;
        double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y *

                PI);

        double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x *

                PI);

        double gg_lon = z * Math.cos(theta);

        double gg_lat = z * Math.sin(theta);

        return new double[]{gg_lon, gg_lat};

    }