下载地图osmdroid地图、osmdroid

2023-09-11 20:24:41 作者:各种姿势各种嗨

我正在开发中,我需要使用离线地图应用程序。我使用osmdroid和osmbonuspack

I am developing an application in which I need to use maps offline. I'm using osmdroid and osmbonuspack

要下载我已经试过了地图:

To download the maps I've tried:

MobileAtlasCreator 但Mapnik的映射锁定。 osmdroid-打包。它的工作原理,但只下载9我放大 MobileAtlasCreator but Mapnik maps are locked. osmdroid-packager. It works, but only download 9 me to zoom

对于我来说,理想的情况是,下载的应用程序本身的地图,我只是想下载你的轨道,而不是一个完整的部分在地图上。

For me the ideal would be to download the maps from the application itself, and I just want to download the maps you are on a track, not a complete section.

我怎么能解决呢?

有没有办法通过我的应用程序下载从手机地图?

Is there any way to download maps from the phone through my application?

推荐答案

正与解决方案 MobileAtlasCreator / MOBAC :

有一个 osmdroid文档,但它是非常薄弱的​​,有时过时。

There is an osmdroid documentation, but it is very weak, and sometimes outdated.

我挣扎在连续的问题时。下面是与osmdroid V4.1一个有效的解决方案的详细信息。

I struggled for a while on successive issues. Here are the details of a working solution with osmdroid v4.1.

1)当MOBAC构建离线地图:

1) When building your offline map with MOBAC:

作为Mapnik的地图都有效地锁定,选择OpenStreetMap的Mapquest服务作为源。 阿特拉斯格式:选择Osmdroid ZIP 小心勾选所有缩放级别,您将需要。默认情况下,没有被选中。

选择您所在的地区,打造你的图谱。这将产生一个zip文件。

Select your area, create your "atlas". This produces a zip file.

上传zip文件您的设备上,在/ SD卡/ osmdroid / (根据设备的确切路径可能会有所不同。如果你已经使用osmdroid,该目录必须已经存在)

Upload the zip file on your device, in /sdcard/osmdroid/ (exact path may vary depending on the device. If you already used osmdroid, this directory MUST already exist)

该文件的名称并不重要。扩展名必须是.ZIP

The file name doesn't matter. The extension MUST be ".zip"

2)现在,在你的osmdroid的应用程序,你的onCreate方法应该是这样的:

2) Now, in your osmdroid application, your onCreate method should be something like this:

@Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    map = (MapView) findViewById(R.id.map);
    map.setTileSource(new XYTileSource("MapQuest",
        ResourceProxy.string.mapquest_osm, 0, 18, 256, ".jpg", new String[] {
            "http://otile1.mqcdn.com/tiles/1.0.0/map/",
            "http://otile2.mqcdn.com/tiles/1.0.0/map/",
            "http://otile3.mqcdn.com/tiles/1.0.0/map/",
            "http://otile4.mqcdn.com/tiles/1.0.0/map/"}));
    map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);
    map.setUseDataConnection(false); //optional, but a good way to prevent loading from the network and test your zip loading. 
    IMapController mapController = map.getController();
    mapController.setZoom(_A ZOOM LEVEL YOU HAVE IN YOUR ZIP_);
    GeoPoint startPoint = new GeoPoint(_POSITION SOMEWHERE INSIDE YOUR MAP_);
    mapController.setCenter(startPoint);
}

在此code,2个参数值是非常重要的:

In this code, 2 parameters values are VERY important:

Mapquest服务的名字(这个确切拼写)是强制性=>这是作为压缩文件内的内部路径。如果你打开​​zip文件,你会看到MOBAC创造了这个MapQuest的目录。

"MapQuest" name (with this EXACT spelling) is MANDATORY => this is used as an internal path inside the zip file. If you open your zip file, you will see that MOBAC created this "MapQuest" directory.

。JPG扩展名是强制=>为MOBAC中以.jpg扩展名的zip创建MapQuest的瓷砖(重要通知,标准砖源osmdroid都使用.png后缀)。

".jpg" extension is also MANDATORY => as MOBAC creates MapQuest tiles in the zip with .jpg extension (important to notice, as standard tile sources in osmdroid are all using ".png" extension).

目前这个阶段,应该没问题 - 只要你是真正为定位于一个领域是你图谱的一部分的MapView(缩放级别和放大器;位置)。

At this stage, it should be OK - as long as you are really positionning the mapview on an area which is part of your atlas (zoom level & position).

3)返回MOBAC ...您还可以选择下面的图集格式:Osmdroid SQLite的或MBTiles SQLite的。 Transfert设备上的文件(Layer.sqlite或Layer.mbtiles)中/ SD卡/ osmdroid /

3) Back to MOBAC... You can also choose the following Atlas formats: "Osmdroid SQLite" or "MBTiles SQLite". Transfert the file (Layer.sqlite or Layer.mbtiles) on the device in /sdcard/osmdroid/

再次在XYTileSource构造方法,扩展名必须是.JPG。这个名字并不重要。

Again, in your XYTileSource constructor, the extension MUST be ".jpg". The name doesn't matter.

这两个工作的罚款。

4)选择Osmdroid GEMF的格式将无法工作:这是一个已知的bug 在GEMF在处理JPG瓷砖。 编辑>在MOBAC,您可以使用自定义瓦块处理功能,JPG砖转换成PNG格式。那么,Osmdroid GEMF都会好的。

4) Choosing "Osmdroid GEMF" format will not work: it's a known bug in GEMF on handling of jpg tiles. EDIT > In MOBAC, you can use the "custom tile processing" feature to convert JPG tiles to PNG format. Then "Osmdroid GEMF" will be ok.