1. 程式人生 > >WebGis開發過程中不同座標系之間的轉換----底圖使用Web墨卡託

WebGis開發過程中不同座標系之間的轉換----底圖使用Web墨卡託

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