1. 程式人生 > >百度地圖瓦片層級範圍對照表

百度地圖瓦片層級範圍對照表

timeout 離線地圖 details style 失敗 java 覆蓋 while 博客

最近搞地圖搞的多,因為項目要求需要做個離線地圖來添加覆蓋物,網上有篇博客教我們怎麽下載瓦片的,對應的是java代碼,但是每次操作去看console裏的層級和範圍超級麻煩,而網上有提供軟件下載,感覺有點慢,所以我覺得兩者結合使用更加給力一點:
先給個java代碼:
地址:https://blog.csdn.net/u012963373/article/details/75155435

package usi.distance.method;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class OutlineMap {
    public static void main(String[] args)
            throws Exception
        {
            String link =
                "http://online3.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl&udt=20180403&scaler=1&p=1";
            int z = 16;//層級
            int xmin = 12489;//x最小值
            int xmax = 13008;//x最大值
            int ymin = 3325;//y最小值
            int ymax = 3997;//y最大值
            int c = 0;//成功數
            int fail = 0;//失敗數量
            for (int i = xmin; i <= xmax; i++)
            {
                for (int j = ymin; j <= ymax; j++)
                {
                    try
                    {
                        URL url = new URL(link.replace("{x}", i + "").replace("{y}", j + "").replace("{z}", z + ""));
                        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
                        conn.setConnectTimeout(100);
                        conn.connect();
                        InputStream in = conn.getInputStream();
                        File dir = new File("d:/mybaidumapdownload1/tiles/" + z + "/" + i);
                        if (!dir.exists())
                        {
                            dir.mkdirs();
                        }
                        File file = new File("d:/mybaidumapdownload1/tiles/" + z + "/" + i + "/" + j + ".png");
                        if (!file.exists())
                        {
                            file.createNewFile();
                        }
                        OutputStream out = new FileOutputStream(file);
                        byte[] bytes = new byte[1024 * 20];
                        int len = 0;
                        while ((len = in.read(bytes)) != -1)
                        {
                            out.write(bytes, 0, len);
                        }
                        out.close();
                        in.close();
//                      System.out.println("已成功下載:" + z + "_" + i + "_" + j + ".jpg");
                        c++;
                    }
                    catch (Exception e)
                    {
                        System.out.println(e.getMessage());
                        fail++;
                    }
                }
            }
            System.out.println("共下載:   " + c + "   張");
            System.out.println("失敗:   " + fail + "   張");
        }

}

技術分享圖片

前面的用下載器比較方便,如果到了15級特別多有時候軟件會卡死,所以用代碼,改變一下參數來下載更加實惠一點

軟件鏈接:https://download.csdn.net/download/sslcbhyso/10281965
要下載積分5個

涉及百度版權,請勿商用,後果自負!

百度地圖瓦片層級範圍對照表