zoukankan      html  css  js  c++  java
  • WGS84经纬度 与 web 墨卡托相互转化 工具类

    package ss;
    /**
     * gis 地图展示工具类
     * 
     * @author zhangss
     * @version 1.0 2017-3-21 15:04:21
     * */
    public class GisUtil {
        private final static double M_PI = Math.PI;
        
        /**
         * WGS84经纬度转web Mercator
         * 
         * @param double lon 经度
         * @param double lat 纬度
         * 
         * @return double[] 
         * */
        public static double[] lonLat2Mercator(double lon, double lat){
            double[] xy = new double[2];
            double x = lon *20037508.342789/180;
            double y = Math.log(Math.tan((90+lat)*M_PI/360))/(M_PI/180);
            y = y *20037508.34789/180;
            xy[0] = x;
            xy[1] = y;
            return xy;
        }
        
        /**
         * web Mercator转WGS84经纬度
         * 
         * @param double mercatorX
         * @param double mercatorY
         * 
         * @return double[] 
         * */
        public static double[] mercator2LonLat(double mercatorX, double mercatorY){
            double[] xy = new double[2];
            double x = mercatorX/20037508.34*180;
            double y = mercatorY/20037508.34*180;
            y= 180/M_PI*(2*Math.atan(Math.exp(y*M_PI/180))-M_PI/2);
            xy[0] = x;
            xy[1] = y;
            return xy;
        }
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            System.out.println("WGS84经纬度转web Mercator");
            System.out.println("mercatorX:  " + GisUtil.lonLat2Mercator(100, 29)[0]);
            System.out.println("mercatorY:  " + GisUtil.lonLat2Mercator(100, 29)[1]);
            
            System.out.println("web Mercator转WGS84经纬度");
            System.out.println("lat:  " + GisUtil.mercator2LonLat(1.1131949079327224E7, 3375646.035778616)[0]);
            System.out.println("lon:  " + GisUtil.mercator2LonLat(1.1131949079327224E7, 3375646.035778616)[1]);
        }
    
    }
  • 相关阅读:
    Yii2中把路由地址中的%2F改为/
    深度解析常用的软件开发模型
    MYSQL索引的类型和索引的方式
    mysql errno 150
    士兵杀敌(五)
    stringstream字符串流
    士兵杀敌(二)(线段树+树状数组)
    士兵杀敌(一)(树状数组)
    C语言文件读写操作总结
    BC第二场
  • 原文地址:https://www.cnblogs.com/zsslll/p/6594504.html
Copyright © 2011-2022 走看看