Search code examples
androidandroid-studioopenstreetmaposmdroidmbtiles

How does Android Studio display an offline map using osmdroid and mbtiles


We are working on an android app that has to display an offline map of one specific location (say 3-7 neighboring islands). We successfully displayed the whole world, but that is too heavy. And when the phone is offline, the map has limited zooming (becomes blurry and it starts lagging).

I envisioned the app to be like Maps.me, wherein if you're offline, you get continuous zooming-in of a downloaded map. Been trying to get my head around https://github.com/osmdroid/osmdroid/wiki/Offline-Map-Tiles and after 2 and a half days, I was able to get mbtiles using Maperitive. But from there, I'm confused on what the next step is. From the github tutorial, I'm stuck here: https://github.com/osmdroid/osmdroid/wiki/Offline-Map-Tiles#using-offline-tile-archives Does this mean I have to manually put the mbtiles to the path or is there a way to store and use the mbtiles automatically (or through code) ?

I just started learning about osm and android studio a few weeks ago and I need help. Badly. Someone please enlighten me.


Solution

    • You can host the tile archives on a server that your provide for your app's users to download
    • You can use the CacheManager utility to enable your users to cache and/or permanently archive tiles for given area before going offline
    • As mentioned by @Josef Adamcik, if the quantity of tiles is small, you can put them directly in /assets/YourTileSourceHere. Then tell osmdroid to use a map tile source matching that name
    • If the tile archive is smallish, you can also put it in raw then on installation copy it out to somewhere osmdroid can read it, such as /data/data/yourpackagename (this is also known as app private storage OR copy to /sdcard/osmdroid or whereever you want, just use Configuration.getInstance().set.... methods to configure the path for it.

    And if you have suggestions for improving the wiki, please let me know