• 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]);
        }
    
    }
  • 相关阅读:
    oracle 动态SQL
    Oracle 学习PL/SQL
    SQL优化原理
    JAVA环境配置
    Java接口
    Java数据类型、操作符、表达式
    C#-VS配置开发环境-摘
    Java版本
    网站构建
    Java 时间、字符串
  • 原文地址:https://www.cnblogs.com/zsslll/p/6594504.html
Copyright © 2020-2023  润新知