Downloading specific maptiles to cache in OSMDroid
Asked Answered
C

2

10

I am currently working on a school project and I am trying to learn the techniques on downloading OSM map tiles into the phone's local memory/cache, so that users are able to view the maps when offline.

This is to be done by giving a specific location, and the map tiles that are within specific radius/distance from the location will be downloaded into the phone memory (when there is online connection) for offline display.

However, I am having some slight trouble in understanding OSMDroid's APIs. From my understanding, it seems that the classes involved are:

Please do correct me if I'm mistaken.

Also, in MapTileBase (which I believe is the provider), the getMapTile returns android.graphics.drawable.Drawable.

Is this Drawable class even related to the concept of offline map display?

Hope someone can enlighten me on where exactly maps are being called to be downloaded into the phone's memory, and how we can edit the maps to display interface items such as routes, pins, etc.

Counterchange answered 19/10, 2012 at 6:32 Comment(1)
possible duplicate of Download maps for osmdroidCedilla
P
1

I don't have an exactly answer as you're looking for a method to cache offline outside of an area the MapView hasn't already navigated to. The built in caching support is there, but not exactly how you want to do it.

You're going to need online download capabilities if you plan to cache and not just supply your own offline map tiles. I would take a look at the MapTileDownloader and maybe try to implement your own version of it. The MapTileDownloader.TileLoader.loadTile() method takes a MapTileRequestState which I believe the MapTileProviderArray calls when a map tile is needed.

If you can replicate the existing MapTileDownloader's TileLoader functionality, you can probably inject your own relative MapTileRequestState or straight up MapTile's to the one requested. e.g. Take the TileLoader called MapTileRequestState, inspect it, figure out how to construct new MapTileRequestState/MapTile representing tiles outside the current view. It won't be easy though as you'll have to deal with the different zoom levels, and depending on the zoom level, the radius should be smaller, etc... A lower zoom level of 18 would have a larger tile radius than a higher 10.

Personally I was recently working on trying to work 100% offline so I don't have any example code to help. Good luck even though its been a couple of months.

Pumpkinseed answered 14/12, 2012 at 6:22 Comment(2)
Thanks for the input anyway =) I kinda solved this problem through downloading specifile MapTiles, and zip them up in the phone for offline display. I managed to get the downloads working for one zoom level but got problems again with multiple zoom levels hereCounterchange
That's too bad. I got offline tiles working just recently as well with an OSMDroid MapView that's constructed from the activity_main.xml instead of the usual onCreate() constructor: #13894767Pumpkinseed
S
0

First, go right the source https://github.com/osmdroid/osmdroid

There's a few wiki articles that will help, especially the offline map tiles article. In short, use MOBAC or the tool osmdroid provides. OSMBonuspack also has a tool to perform the same task on device.

Map tiles are actually downloaded using this class https://github.com/osmdroid/osmdroid/blob/master/osmdroid-android/src/main/java/org/osmdroid/tileprovider/modules/MapTileDownloader.java

Sallyanne answered 19/12, 2015 at 13:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.