简体   繁体   中英

How to use OSM offline maps saved on external SD?

I currently try to develop an Android application that uses osm offline maps. 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.

Unfortunately, I'm not able to find the external sd-card within the ddms-file-explorer of eclipse. I only found the internal sd.

I copied the osmdroid.zip to the external sd using the windows explorer, but my application couldn't find it. I also wrote my own subversion of osmdroid as library to choose a specific path, but without results. 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.

osmdroid use by default the external sdcard to load offline maps as they are loaded from the osmdroid directory defined in OpenStreetMapTileProviderConstants:

/** 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.

There's a good explanation of how osmdroid works with offline maps here: https://stackoverflow.com/a/8286276/891479

Use MapTileProviderBasic in your app. Some examples here: 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:

/tilesourcename/zoomlevel/...

In Galaxy S2 the external sd card i normally located in /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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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