2

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:

/sdcard/application-name/uuid/tiles

and I have set the OSM cache like so:

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

I then set up the TileSource:

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

and the TileProvider:

tileProvider = new MapTileProviderBasic(getActivity());
tileProvider.setTileSource(tileSource);

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(Random.java:175)
at org.osmdroid.tileprovider.tilesource.OnlineTileSourceBase.getBaseUrl(OnlineTileSourceBase.java:33)
at org.osmdroid.tileprovider.tilesource.XYTileSource.getTileURLString(XYTileSource.java:19)
at org.osmdroid.tileprovider.modules.MapTileDownloader$TileLoader.loadTile(MapTileDownloader.java:171)
at org.osmdroid.tileprovider.modules.MapTileModuleProviderBase$TileLoader.run(MapTileModuleProviderBase.java:291)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)

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! Thanks.

5
  • Have you tried writing the path yourself to see what happens?
    – M. Haché
    Commented Aug 3, 2016 at 13:40
  • I don't think the path is the problem, when I hardcoded it, it still failed. I think the problem lies with the Source or the Provider.
    – Nome
    Commented Aug 3, 2016 at 15:17
  • I'll come back to you in a couple hours if I see anything, will have to compare with my code because I feel mine wasn't much different from yours.
    – M. Haché
    Commented Aug 3, 2016 at 16:53
  • Thanks @M.Haché, have you had a look at your code?
    – Nome
    Commented Aug 8, 2016 at 8:29
  • Try setting up an sample URL on your tilesource. Instead of ITileSource tileSource = new XYTileSource ("tiles", 0, 18, 256, ".png", new String[]{}); try ITileSource tileSource = new XYTileSource ("tiles", 0, 18, 256, ".png", new String[]{"http://i.dont.care.org/"});
    – M. Haché
    Commented Aug 8, 2016 at 20:35

2 Answers 2

4

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

/sdcard/osmdroid/uuid/tiles

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.

1
  • What will happen if you don't have a sdcard in your device? Commented Jul 19, 2019 at 8:46
2

I had this issue on a device which does not have a default "uuid" folder (8" Samsung Tab 4) when trying to use a MOBAC-generated .zip file. I found a solution at the link below, but the gist is this:

  1. Unzip the MOBAC-generated .zip file, and re-zip only the directory which contains tile zoom-level subdirectories (e.g., the ones labeled "10", "11", etc.)
  2. Place the new zip in the osmdroid directory. NOT in osmdroid\tiles\.
  3. In your code, reference the specific TileSourceFactory sub-type for the source which you used to generate the atlas. This worked for me (when using the OpenStreetMap public transport layer): map.setTileSource(TileSourceFactory.PUBLIC_TRANSPORT);

This could be used in conjunction with a check to see if the device has a data connection:

// Check for data connection and use offline map if necessary
    if (Main.deviceIsOnline()) {
        map.setTileSource(TileSourceFactory.MAPNIK);
        //map.setTileSource(TileSourceFactory.USGS_SAT);
        //map.setTileSource(TileSourceFactory.USGS_TOPO);
    } else {
        map.setTileSource(TileSourceFactory.PUBLIC_TRANSPORT);
    }

Here is the link:

https://mobiledevstories.wordpress.com/2014/02/27/osmdroid-mobile-atlas-creator-tutorial/

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.