简体   繁体   English

如何使用保存在外部SD上的OSM离线地图?

[英]How to use OSM offline maps saved on external SD?

I currently try to develop an Android application that uses osm offline maps. 我目前正在尝试开发一个使用osm离线地图的Android应用程序。 I'd like to provide a large number of offline maps. 我想提供大量的离线地图。 That's why I decided to use the external SD-Card of my Galaxy S2 as folder of the tile source. 这就是为什么我决定使用我的Galaxy S2的外部SD卡作为磁贴源的文件夹。

Unfortunately, I'm not able to find the external sd-card within the ddms-file-explorer of eclipse. 不幸的是,我无法在eclipse的ddms-file-explorer中找到外部SD卡。 I only found the internal sd. 我只发现了内部的SD。

I copied the osmdroid.zip to the external sd using the windows explorer, but my application couldn't find it. 我使用Windows资源管理器将osmdroid.zip复制到外部sd,但我的应用程序找不到它。 I also wrote my own subversion of osmdroid as library to choose a specific path, but without results. 我还写了我自己的osmdroid颠覆作为库来选择一个特定的路径,但没有结果。 Probably, I didn't try the appropriate path. 可能,我没有尝试适当的路径。

I hope, that there is anybody out there, who can describe me, how to use the external sd as a storage for tiles. 我希望,那里有人可以形容我,如何使用外部sd作为瓷砖的存储。

osmdroid use by default the external sdcard to load offline maps as they are loaded from the osmdroid directory defined in OpenStreetMapTileProviderConstants: osmdroid默认使用外部sdcard来加载离线地图,因为它们是从OpenStreetMapTileProviderConstants中定义的osmdroid目录加载的:

/** Base path for osmdroid files. Zip files are in this folder. */
public static final File OSMDROID_PATH = new File(Environment.getExternalStorageDirectory(),
        "osmdroid");

To load your maps you can use MapTileFileArchiveProvider or directly MapTileProviderBasic that uses MapTileFileArchiveProvider itself. 要加载地图,您可以使用MapTileFileArchiveProvider或直接使用MapTileFileArchiveProvider本身的MapTileProviderBasic。

There's a good explanation of how osmdroid works with offline maps here: https://stackoverflow.com/a/8286276/891479 这里有一个很好的解释osmdroid如何使用离线地图: https ://stackoverflow.com/a/8286276/891479

Use MapTileProviderBasic in your app. 在您的应用中使用MapTileProviderBasic。 Some examples here: http://www.androidadb.com/class/ma/MapTileProviderBasic.html 这里有一些例子: http//www.androidadb.com/class/ma/MapTileProviderBasic.html

If your tiles are not loaded this is also perhaps because the directory structure inside your zip is wrong, don't forget to set the tile source name as base directory: 如果您的磁贴未加载,这也可能是因为您的zip中的目录结构错误,请不要忘记将磁贴源名称设置为基本目录:

/tilesourcename/zoomlevel/... / tilesourcename /缩放级别/ ...

In Galaxy S2 the external sd card i normally located in /sdcard/external_sd . 在Galaxy S2中,外部SD卡通常位于/sdcard/external_sd So you could open the file by specifying its path: 因此,您可以通过指定其路径来打开该文件:

File myFile = new File(/sdcard/external_sd/osmdroid.zip);

and then you could read the file normally, though in your case you probably want to use a ZipFile to read the contents of the zip. 然后你可以正常读取文件,但在你的情况下你可能想使用ZipFile来读取zip的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM