How to read maps offline in OSMDroid

3626 views
Skip to first unread message

Rodrigo Cericatto

unread,
Apr 2, 2014, 9:56:18 AM4/2/14
to osmd...@googlegroups.com

Hello everyone.

My name is Rodrigo Cericatto and I'm an Android Developer that's trying to implement offline maps in Android. In the last 13 days I'm researching how to do it, with no success.


1) I tried putting a .osm map file into the /mnt/sdcard/osmdroid/ folder (as researched in the links below):

http://www.haakseth.com/?p=30

http://www.gleisarbeiter.de/2011/03/18/offline-maps-using-mobile-atlas-creator-and-usage-on-android/

But the map is not showed. Just appears a white color!


2) I tried using links like the ones below, but again, the maps stayed white.

http://blog.spatialnetworks.com/post/2012/07/using-mbtiles-on-android-with-osmdroid

http://www.sieswerda.net/2012/08/13/integrating-osmdroid-part-2/


3) I've created an Stack Overflow topic, asking about it. But still I got no solution:

http://stackoverflow.com/questions/22669509/how-to-read-maps-offline-in-osmdroid


So, what am I missing? It's so weird because OSMDroid calculates routes, shows overlays, do everything, except show offline maps. And if almost everybody uses OSMDroid, there must be a way to obtain offline maps! If weren't a way, nobody would be using, right?


I've found a lot of links in web saying that or option 1) works, or 2). I've tested this applications into a Motorola Atrix (Android 2.3.6) and a Google Nexus 4 (Android 4.4.2). But for me, nothing works.

I've also researched into the OSMDroid forum:

https://groups.google.com/forum/#!searchin/osmdroid/offline

Unfortunatelly, again, I got no success.


So, I'm asking here into the forum for a link or source code (working) of an offline map that is showed by OSMDroid, without staying white.

Martin

unread,
Apr 3, 2014, 3:36:06 AM4/3/14
to osmd...@googlegroups.com
If you want to use the MapsForge rendering engine to generate offline tiles on the fly (on the device) from open street map data have a read of this thread:
https://groups.google.com/forum/#!searchin/osmdroid/mapsforge/osmdroid/gSieR9BF_z0/3BIIhvN95TMJ

I have this working with OSMDroid version 4.1, it's not perfect as it runs in a single thread so performance is not optimal.
But it does work!

Take a look at this java Eclipse project:
http://b4a.martinpearman.co.uk/osmdroid/OSMDroid_4_1_MapsForgeTileSource-20140403.zip

All the org.mapsforge.* packages contain the classes you need.
The uk.co.martinpearman.b4a.mapsforge.* packages contain classes that enable the rendering engine to be used in Basic4Android and are not required for a 'standard' java android application:
http://www.basic4ppc.com/index.html

You'd need to:

1) Add the org.mapsforge.* packages and the 'assets' file to your project.

2) Create an instance of MapsForgeTileSource and pass it to the TileSourceFactory addTileSource method.

3) In order for this to work i had to modify one OSMDroid class: org.osmdroid.tileprovider.MapTileProviderBasic

Lines #65 to #71 show the modification:

try{
    final NetworkAvailabliltyCheck networkAvailablityCheck=(NetworkAvailabliltyCheck) aNetworkAvailablityCheck;
    final MapsForgeTileProvider mapsforgeProvider = new MapsForgeTileProvider(null, networkAvailablityCheck);
    mTileProviderList.add(mapsforgeProvider);
} catch (NoClassDefFoundError e){
    //    MapsforgeTileProvider not available
}

So you need to compile your project using the OSMDroid source code, replacing the original MapTileProviderBasic with my modified version.
(You can't use the OSMDroid .jar file).

You can read more about MapsForge here:
https://code.google.com/p/mapsforge/
And the wiki page explains how to create the required 'map database' file:
https://code.google.com/p/mapsforge/wiki/GettingStartedMapWriter

Martin.

emux

unread,
Apr 3, 2014, 8:10:35 AM4/3/14
to osmd...@googlegroups.com
Osmdroid library can render raster tiles (i.e. png, jpg tile images) from an online tile provider
or from offline structures like directory pyramid, zip file or sqlite / mbtiles database.
It is not intended to read directly OSM or other vector data.

So the guides you mentioned say specifically what atlas format to choose at MOBAC,
'Osmdroid ZIP', Osmdroid SQLite', 'MBTiles SQLite',
where to put the offline file and how to set the tile source to map view.

Also pay attention at AndroidManifest's permissions here.

--
Emux
Cruiser

MKergall

unread,
Apr 4, 2014, 1:10:46 PM4/4/14
to osmd...@googlegroups.com
Hi Rodrigo,

Yes, it's feasible, but not completely straightforward...

You will find an up-to-date answer here: http://stackoverflow.com/questions/22862534/download-maps-for-osmdroid

Mathieu

Terence Stigers

unread,
Apr 6, 2014, 7:16:47 PM4/6/14
to osmd...@googlegroups.com
I've had no trouble with this.  If you turn off the data feed [mapView.setUseDataConnection(false);] and drop a TileMill .mbtiles file in /sdcard/osmdroid it should work without a hitch. Here's a post I wrote about this a while back (including code): http://wherewithal1.wordpress.com/2013/03/06/field-maps/ The post dealt with an older version of OSMDroid, but I have successfully done the same with the latest version.

Rodrigo Cericatto

unread,
Apr 6, 2014, 11:37:55 PM4/6/14
to osmd...@googlegroups.com
So Terence, it didn't worked for me!
I followed all your tutorial, but it didn't worked.
What I'm missing?
Could you send me your source code (with the map) for graff...@gmail.com, for I try to make this finally work?
I've been trying for already 3 weeks, and I never got and OSM offline map working...

Rodrigo Cericatto

unread,
Apr 7, 2014, 12:17:51 AM4/7/14
to osmd...@googlegroups.com
Mathieu, IT FINALLY WORKED FOR ME!!!
Thanks SO MUCH for your response!!!

Terence Stigers

unread,
Apr 7, 2014, 9:59:13 AM4/7/14
to osmd...@googlegroups.com
I'm just guessing here, but I'm inclined to think that your problem stemmed from your map, not from OSMDroid.  I wouldn't be at all surprised if your map and your device just happened to be at divergent coordinates.  I had this problem myself a while back.  Now I have a small mbtiles map of my town (centered on my house) that I use as a working map when I'm developing.  It has saved me a lot of headaches.

baraka shaban

unread,
Mar 25, 2019, 3:51:54 PM3/25/19
to osmdroid
Hello Rodrigo Cericatto I have the same problem and my aim is to implement offline map in android studio using odmdroid. As I followed you in your post I saw finally you have got a solution for that problem. So please can you help me procedure and even source code on how to implement offline maps. my email address is baraka...@gmail.com
Reply all
Reply to author
Forward
0 new messages