• 由经纬度坐标得到腾讯地图的瓦片/切片行列号


    参考: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可直接访问,测试坐标为浙江大学西溪校区主教学楼门口的圆盘。

  • 相关阅读:
    [component]button skin–按钮组件外观
    as3 图片平滑方法
    SOLVED: Right Click in AS3
    一个超高效的不规则物体碰撞检测的类
    flex中的css应用
    控制时间间隔
    用flash cs3美化flex3之skin开发
    AS3实现RPG游戏鼠标8方向操作
    log4net basic example write to file
    观察者模式(C#实现 + eventhandler)
  • 原文地址:https://www.cnblogs.com/qdhotel/p/9365560.html
Copyright © 2020-2023  润新知