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]);
        }
    
    }
  • 相关阅读:
    J2EE开发环境
    Java核心api
    SCJP (SUN认证Java程序员)
    蓝领”变“金领”
    阿飞正传
    高效项目的七个习惯转载
    写程序的一些感想和教训(转载)
    学习的过程也是迭代的过程
    管理的艺术
    怎样成为优秀的软件模型设计者?[精华]
  • 原文地址:https://www.cnblogs.com/zsslll/p/6594504.html
Copyright © 2011-2022 走看看