zoukankan      html  css  js  c++  java
  • 由经纬度坐标得到腾讯地图的瓦片/切片行列号

    参考:https://blog.csdn.net/mygisforum/article/details/22997879

       https://blog.csdn.net/u013929284/article/details/53614281

       https://blog.csdn.net/shaxiaozilove/article/details/54908569

    项目需要根据数据的瓦片行列号建立文件目录,而已知的位置信息是经纬度,下面是解决方法:

    一、经纬度坐标 => 投影坐标;腾讯地图使用的是Web Mercator投影。

        private double[] getXY(double lon, double lat) {
            double earthRad = 6378137.0;
            double x = lon * Math.PI / 180.0 * earthRad;
            double a = lat * Math.PI / 180.0;
            double y = earthRad / 2.0 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));
            return new double[]{x, y};
        }

    二、腾讯地图坐标原点在左下角,根据瓦片级数求出瓦片长宽;18级代表该级数下,每行每列的瓦片数为Math.pow(2,18)。

    三、计算行列号,即投影坐标值之差 / 瓦片大小;下为完整代码,其中-85.05112877980659, -180是原点的经纬度。

            double[] sz = getXY(120.141554 ,30.273926);
            int z = 18;
            double[] bl = getXY(-180, -85.05112877980659);
            double[] tl = getXY(-180, 85.05112877980659);
            double[] br = getXY(180, -85.05112877980659);
            System.out.println(String.format("坐标BL点:%f,%f", bl[0], bl[1]));
            System.out.println(String.format("坐标TL点:%f,%f", tl[0], tl[1]));
            System.out.println(String.format("坐标BR点:%f,%f", br[0], br[1]));
            System.out.println(String.format("深圳坐标:%f,%f", sz[0], sz[1]));
            double w = (br[0] - bl[0]) / Math.pow(2, z);//格网宽度
            double h = (tl[1] - bl[1]) / Math.pow(2, z);//格网高度
            System.out.println(String.format("格网大小:%f x %f", w, h));
            int[] gridxy = new int[2];
            int c = (int) ((sz[0] - bl[0]) / w);
            int r = (int) ((sz[1] - bl[1]) / h);
            System.out.println(String.format("对应行列号:%d,%d", c, r));
            double c_d = Math.floor(c / 16.0);
            double r_d = Math.floor(r / 16.0);
            System.out.println(String.format("对应请求url:http://p3.map.gtimg.com/maptilesv2/%d/%d/%d/%d_%d.png", z, (int) c_d, (int) r_d, c, r));

    最后的url可直接访问,测试坐标为浙江大学西溪校区主教学楼门口的圆盘。

  • 相关阅读:
    Bootstrap标签(label)的使用
    Docker学习(二)
    linux 的tee命令
    解决 Docker pull 出现的net/http: TLS handshake timeout 的一个办法
    win 10 安装.msi 程序出现the error code is 2503
    Kbuntu16.04利用快捷键调用终端Konsole
    ubuntu上swift开发学习2
    ubuntu上swift开发学习1
    Linux中常用文件传输命令及使用方法
    Kbuntu16.04添加工作空间
  • 原文地址:https://www.cnblogs.com/qdhotel/p/9365560.html
Copyright © 2011-2022 走看看