在以前网上经常介绍使用MobileAtlasCreator 下载地图碎片做离线地图,现在可以采用OSMMapTilePackager下载地图碎片,实现地图离线地图的碎片生成.
官方地址:
http://code.google.com/p/osmdroid/wiki/HowToUsePackager
详细官方介绍如下
This page explains how to use the osmdroid tile packager.
You will probably find it easier to use MobileAtlasCreator instead of this
You can use the tile packager in order to load tiles onto your device so that you will not need an internet connection when running an application that uses osmdroid.
The first thing you need to do is to decide the area that you want to download. This means determining the coordinates. The easiest way is to go to OpenStreetMap.org, view the area that you want to download, and then click on the "Export" tab. You can then click the "Manually select a different area" link and choose your area by dragging a box over it. The coordinates are displayed in the "Area to Export" box.
Below is an example of choosing the lovely town of Haarlem in The Netherlands. This shows that the coordinates are:
North: 52.4244
East: 4.6746
South: 52.3388
West: 4.5949
Download osmdroid-packager-x.xx.jar.
Here is an example command line to download the area selected in the example above:
第两种方式
1.设置环境变量
参数的详细解释:
Here's what the parameters mean:
-u | http://tile.openstreetmap.org/%d/%d/%d.png | This is the pattern for tiles for the Mapnik format. |
-t | Mapnik | Location of the temporary download location. This should be the renderer name if you intend to use the zip directly in osmdroid. |
-d | haarlem.zip | Zip file to create when finished. |
-zmax | 18 | Maximum zoom level to download tiles for. |
The -d parameter is optional, in which case it won't create a zip file. In that case it also won't delete the temp files, since these are actually the required result. You can also use a .gemf or .sqlite extension in which case it will create an archive of the corresponding type.
Just copy the zip to /sdcard/osmdroid on your device.
本文相关内容只用于个人研究,若用于商业请自行负责。
1. 下载Google地图切片到本地:如果没有要求地图显示中文,则可以用Google Maps Downloader下载Google地图到本地;如果要显示中文地图,则要用China Google Maps Downloader
2. 在tomcat服务器建个项目gmcn,为了方便查找文件,将文件按照zoom/x存放,如图:
3. 利用OpenLayers.Layer.TMS显示地图,重点是get_my_url()找到要显示的切片
<html> <head> <title>Google Local Tiles</title> <link rel="stylesheet" href="css/style.css" type="text/css" /> <script src="js/OpenLayers/lib/OpenLayers.js"></script> <script type="text/javascript"> var map, layer; //complex object of type OpenLayers.Map //Initialise the 'map' object function init() { map = new OpenLayers.Map("map", { maxExtent : new OpenLayers.Bounds(-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892), numZoomLevels : 18, maxResolution : 156543.0339, units : 'm', projection : "EPSG:900913", displayProjection : new OpenLayers.Projection("EPSG:4326") }); layer = new OpenLayers.Layer.TMS("Name", "http://10.0.0.239:8081/gmcn/", { 'type' : 'png', 'getURL' : get_my_url }); map.addLayer(layer); map.addControl(new OpenLayers.Control.Scale()); map.addControl(new OpenLayers.Control.MousePosition()); map.addControl(new OpenLayers.Control.LayerSwitcher()); var lonLat = new OpenLayers.LonLat(117.62519, 39.52329); lonLat.transform(map.displayProjection, map.getProjectionObject()); map.setCenter(lonLat, 8); } function get_my_url(bounds) { var res = this.map.getResolution(); var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w)); var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h)); var z = this.map.getZoom(); var path = "" + z + "/" + x + "/gmcn_" + x + "_" + y + "_" + z + "." + this.type; var url = this.url; if (url instanceof Array) { url = this.selectUrl(path, url); } return url + path; } </script> </head> <!-- body.onload is called once the page is loaded (call the 'init' function) --> <body onload="init();"> <!-- define a DIV into which the map will appear. Make it take up the whole window --> <div style="width: 100%; height: 100%" id="map"></div> </body> </html>
参考: