Nome Nome - 9 months ago 85
Android Question

OSMdroid - unable to load offline map tiles from custom location

I have looked around and can't find an answer to what I hope is quite a simple thing to achieve this question seemed similar but has no replies! So the problem is this; I have my offline map tiles on the android device here:


and I have set the OSM cache like so:

File applicationDir = new File(Environment.getExternalStorageDirectory(), File.separator + "application-name" + File.separator + "uuid" + File.separator);

I then set up the TileSource:

ITileSource tileSource = new XYTileSource ("tiles", 0, 18, 256, ".png", new String[]{});

and the TileProvider:

tileProvider = new MapTileProviderBasic(getActivity());

When I run my app, I get a succession of these:

Error downloading MapTile: /15/16000/9960
java.lang.IllegalArgumentException: n <= 0: 0
at java.util.Random.nextInt(
at org.osmdroid.tileprovider.tilesource.OnlineTileSourceBase.getBaseUrl(
at org.osmdroid.tileprovider.tilesource.XYTileSource.getTileURLString(
at org.osmdroid.tileprovider.modules.MapTileDownloader$TileLoader.loadTile(
at org.osmdroid.tileprovider.modules.MapTileModuleProviderBase$
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$

Presumably because the local tiles aren't found and the MapTileProviderBasic ultimately falls to the MapTileDownloader and it barfs because there are no online tiles.

Any suggestions gratefully received!


So I eventually sorted this out by using the OSMDroid default location on the device


and set the tile source like so

ITileSource tileSource = new XYTileSource(uuid, 0, 17, 256, ".png", new String[0]);

osmdroid looks inside the directory uuid for a subdirectory called 'tiles', although the documentation kind of tells you this, it's not very explicit. I think you could probably use any location on the sdcard using this approach, I just decided to use the simplest solution.