WebGis开发过程中不同坐标系之间的转换----底图使用Web墨卡托

版权声明:本文为博主原创文章,未经博主允许不得转载。https://mp.csdn.net/configure https://blog.csdn.net/qq_17165243/article/details/84286264

web 墨卡托和经纬度投影转化的代码

/**
     * 经纬度坐标转Web墨卡托坐标
     * @param lat
     * @param lon
     * @return
     */
    public static  double [] lonLat2Mercator(double lat,double lon){

        double [] xy = new double[2];
        double x = lon * 20037508.342789 / 180;
        double y = Math.log(Math.tan((90+lat)*Math.PI/360))/(Math.PI/180);
        y = y * 20037508.342789 / 180;
        xy[0] = x;
        xy[1] = y;
        return  xy;
    }

    /**
     * Web墨卡托坐标转经纬度
     * @param mercatorX
     * @param mercatorY
     * @return
     */
    public static double [] mercator2lonLat(double mercatorX,double mercatorY ){
        double [] xy = new double[2];
        double x = mercatorX/20037508.342789*180;
        double y = mercatorY/20037508.342789*180;
        y = 180 /Math.PI*(2*Math.atan(Math.exp(y*Math.PI/180))-Math.PI/2);
        xy[0] = x;
        xy[1] = y;
        return xy;
    }
--------------------- 

原文:https://blog.csdn.net/liuxu841911548/article/details/78569519 
 

猜你喜欢

转载自blog.csdn.net/qq_17165243/article/details/84286264