Android Question best way to get off-line maps for OSMDroid?

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Using OSMDroid 4.1 on a Samsung S9 and all working well, but need off-line maps as connection can be poor.
Had a go with various applications, Mobac, Maperitive and also MapsForge as suggested in this post:
https://www.b4x.com/android/forum/threads/mobac-supports-mapsforge-for-offline-tiles.53277/#content
All causing different problems. MapsForge, just didn't allow me to download England. I only need small area of the UK, about 10 x 10 km around Tettenhall, Wolverhampton (lat: 52.5514 to 52.652, lon: -2.0648 to -2.0648). I need a good zoom level, say 22.
I can store the files on the SD.

Any good instructions what the best way is how to do this is?

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Using OSMDroid 4.1 on a Samsung S9 and all working well, but need off-line maps as connection can be poor.
Had a go with various applications, Mobac, Maperitive and also MapsForge as suggested in this post:
https://www.b4x.com/android/forum/threads/mobac-supports-mapsforge-for-offline-tiles.53277/#content
All causing different problems. MapsForge, just didn't allow me to download England. I only need small area of the UK, about 10 x 10 km around Tettenhall, Wolverhampton (lat: 52.5514 to 52.652, lon: -2.0648 to -2.0648). I need a good zoom level, say 22.
I can store the files on the SD.

Any good instructions what the best way is how to do this is?

RBS

Some progress with this and now have a SQLite file with I guess tiles of the mentioned area. Made with Mobac.
Size is about 17Mb. File name is Practice.sqlite
I copied this to the phone's SD card in folder of my application. I tried directly in this folder and also in a sub-folder,
called OSMDroid. Tile source is set like this:

B4X:
MapView1.SetTileSource(TileSourceFactory1.GetTileSource("Practice.sqlite"))

'also tried:
MapView1.SetTileSource(TileSourceFactory1.GetTileSource("Practice"))

Sofar no success and getting this error:
java.lang.IllegalArgumentException: No such tile source: Practice.SQLite

Where should this SQLite file be located?
What should the code be for SetTileSource?


RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Some progress with this and now have a SQLite file with I guess tiles of the mentioned area. Made with Mobac.
Size is about 17Mb. File name is Practice.sqlite
I copied this to the phone's SD card in folder of my application. I tried directly in this folder and also in a sub-folder,
called OSMDroid. Tile source is set like this:

B4X:
MapView1.SetTileSource(TileSourceFactory1.GetTileSource("Practice.sqlite"))

'also tried:
MapView1.SetTileSource(TileSourceFactory1.GetTileSource("Practice"))

Sofar no success and getting this error:
java.lang.IllegalArgumentException: No such tile source: Practice.SQLite

Where should this SQLite file be located?
What should the code be for SetTileSource?


RBS

Still not fixed this. I had a look at this:
https://github.com/osmdroid/osmdroid/wiki/Offline-Map-Tiles

and understand that the folder layout for off-line maps should be like this:

/sdcard/osmdroid/
myOsmdroidDatabase.sqlite
/sdcard/osmdroid/tiles/

Have done this and my SQLite db is in /sdcard/osmdroid/
The name of this SQLite db is tmp.sqlite
I can see this SQLite db has the right structure, so the right naming convention.
I have tried numerous ways to access this db, but all failing with the following error:
java.lang.IllegalArgumentException: No such tile source: tmp.sqlite
Instead of tmp.sqlite I also tried with just tmp.
I am using OSMDroid, version 4.1.

This is the code (one of many tries) to show the map:

B4X:
Sub ShowMap
 
 Dim arrCoordinates() As Double
 Dim TileSourceFactory1 As OSMDroid_TileSourceFactory
 Dim TS As OSMDroid_TileSource

  If File.ExternalWritable=False Then
  ' OSMDroid requires the use of external storage to cache tiles
  ' if no external storage is available then the MapView will display no tiles
  General.RunLog("WARNING, NO EXTERNAL STORAGE AVAILABLE")
  Return
 End If
 
 Dim GeoPoint1 As OSMDroid_GeoPoint
 
 arrCoordinates = GetCoordinates
 General.RunLog("ShowMap, Lat: " & arrCoordinates(0) & ", Lon: " & arrCoordinates(1))

 GeoPoint1.Initialize(arrCoordinates(0), arrCoordinates(1))

 MapView1.Initialize("")
 MapView1.SetUseDataConnection(False)
 
'>>>> error here: java.lang.IllegalArgumentException: No such tile source: tmp.sqlite
 TS = TileSourceFactory1.GetTileSource("tmp.sqlite") 'tried also "tmp"
 
 General.RunLog("ShowMap, TS.Name: " & TS.Name)

 MapView1.SetTileSource(TS)
 MapView1.SetMaxZoomLevel(24)
 'MapView1.SetBuiltInZoomControls(True)
 MapView1.SetMultiTouchControls(True)
 
 'set the zoom before the center
 MapView1.GetController.SetZoom(18)
 MapView1.GetController.SetCenter(GeoPoint1)
 
 pnlMap.AddView(MapView1, 12, 0, pnlMap.Width, pnlMap.Height)
 
 GotoPanel(ePanelType.ShowMap, False)
 
End Sub


Any suggestions what is going wrong here?
Any insight in this very greatly appreciated!


RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Still not fixed this. I had a look at this:
https://github.com/osmdroid/osmdroid/wiki/Offline-Map-Tiles

and understand that the folder layout for off-line maps should be like this:

/sdcard/osmdroid/
myOsmdroidDatabase.sqlite
/sdcard/osmdroid/tiles/

Have done this and my SQLite db is in /sdcard/osmdroid/
The name of this SQLite db is tmp.sqlite
I can see this SQLite db has the right structure, so the right naming convention.
I have tried numerous ways to access this db, but all failing with the following error:
java.lang.IllegalArgumentException: No such tile source: tmp.sqlite
Instead of tmp.sqlite I also tried with just tmp.
I am using OSMDroid, version 4.1.

This is the code (one of many tries) to show the map:

B4X:
Sub ShowMap
 
 Dim arrCoordinates() As Double
 Dim TileSourceFactory1 As OSMDroid_TileSourceFactory
 Dim TS As OSMDroid_TileSource

  If File.ExternalWritable=False Then
  ' OSMDroid requires the use of external storage to cache tiles
  ' if no external storage is available then the MapView will display no tiles
  General.RunLog("WARNING, NO EXTERNAL STORAGE AVAILABLE")
  Return
 End If
 
 Dim GeoPoint1 As OSMDroid_GeoPoint
 
 arrCoordinates = GetCoordinates
 General.RunLog("ShowMap, Lat: " & arrCoordinates(0) & ", Lon: " & arrCoordinates(1))

 GeoPoint1.Initialize(arrCoordinates(0), arrCoordinates(1))

 MapView1.Initialize("")
 MapView1.SetUseDataConnection(False)
 
'>>>> error here: java.lang.IllegalArgumentException: No such tile source: tmp.sqlite
 TS = TileSourceFactory1.GetTileSource("tmp.sqlite") 'tried also "tmp"
 
 General.RunLog("ShowMap, TS.Name: " & TS.Name)

 MapView1.SetTileSource(TS)
 MapView1.SetMaxZoomLevel(24)
 'MapView1.SetBuiltInZoomControls(True)
 MapView1.SetMultiTouchControls(True)
 
 'set the zoom before the center
 MapView1.GetController.SetZoom(18)
 MapView1.GetController.SetCenter(GeoPoint1)
 
 pnlMap.AddView(MapView1, 12, 0, pnlMap.Width, pnlMap.Height)
 
 GotoPanel(ePanelType.ShowMap, False)
 
End Sub


Any suggestions what is going wrong here?
Any insight in this very greatly appreciated!


RBS

Still not fixed this, tried also with 4uMaps for the tile source name instead of the database name.
Not sure what this name should be.
Is there anybody on this forum who has successfully connected to a map stored like this in SQLite database?
I understand it is the recommended way to store like this with Mobac, but I can't make it work?

RBS
 
Upvote 0

gravel

Member
Licensed User
Longtime User
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Don't know if this will be of any help. But I do remember that when I gave it a go I used http://extract.bbbike.org/?format=mapsforge-osm.zip to generate a bespoke area, it's excellent as long as you don't mind cycle maps and don't want a huge area, and [thanks] warwound provided an example of a mapsforgetilesource on his website http://b4a.martinpearman.co.uk/osmdroid/ in MapsForgeTileSource 20140308.zip (not the most recent there).

Thanks, will have look at that.
What I need though is figuring out how
to connect to a sqlite map database file.
I think making the file is not the problem.

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Don't know if this will be of any help. But I do remember that when I gave it a go I used http://extract.bbbike.org/?format=mapsforge-osm.zip to generate a bespoke area, it's excellent as long as you don't mind cycle maps and don't want a huge area, and [thanks] warwound provided an example of a mapsforgetilesource on his website http://b4a.martinpearman.co.uk/osmdroid/ in MapsForgeTileSource 20140308.zip (not the most recent there).

I went to that site and downloaded my area:

Area: 'practice_area' covers 197 square km
Coordinates: -2.32,52.551 x -2.06,52.652
Format: Mapsforge OSM
Only a small file, practice_area.map, size about 2.7 Mb.

All nice and simple.
I then converted to an OSMDroid SQLite file as explained here:
https://www.b4x.com/android/forum/threads/mobac-supports-mapsforge-for-offline-tiles.53277/

This worked well after altering the .xlm.
As the zoom level went up quite high I ended up with a large file, some 247 Mb.

I now have the same problem though that I can't load this file with the usual message:
java.lang.IllegalArgumentException: No such tile source: tmp (tried various strings here).

For a moment I thought that I could load the file after doing this (OSMDroid version 4.1):

B4X:
MapView1.SetTileSource(TileSourceFactory1.GetTileSource2(0))

This though loads the cached Mapnik data.

So, no progress really and very frustrating.

RBS
 
Upvote 0

js486dog

Active Member
Licensed User
Longtime User
I went to that site and downloaded my area:

Area: 'practice_area' covers 197 square km
Coordinates: -2.32,52.551 x -2.06,52.652
Format: Mapsforge OSM
Only a small file, practice_area.map, size about 2.7 Mb.

All nice and simple.
I then converted to an OSMDroid SQLite file as explained here:
https://www.b4x.com/android/forum/threads/mobac-supports-mapsforge-for-offline-tiles.53277/

This worked well after altering the .xlm.
As the zoom level went up quite high I ended up with a large file, some 247 Mb.

I now have the same problem though that I can't load this file with the usual message:
java.lang.IllegalArgumentException: No such tile source: tmp (tried various strings here).

For a moment I thought that I could load the file after doing this (OSMDroid version 4.1):

B4X:
MapView1.SetTileSource(TileSourceFactory1.GetTileSource2(0))

This though loads the cached Mapnik data.

So, no progress really and very frustrating.

RBS

A)

You need to use only these formats for osmdroid offline in MOBAC :
MBTiles SQLite
Osmdroid ZIP
Osmdroid GEMF
Osmdroid SQLite

SQLITE for LOCUS is different like SQLITE for osmdroid.

B)

I have not been successful to read osmdroid maps from micro SD Card.
If you find the way to read the osmdroid offline maps from micro SD Card, please share the solution with me.

Raster map files have to be in the "osmdroid" folder in the Internal (shared) storage (no micro SD card).
Create the folder with the name osmdroid in the Internal (shared) storage and copy the map files (SQLite, GEMF ....) in it.
Do not create the Mapnik subfolder. Create only osmdroid folder with the map files in it.


B4A code is somethink like this:

MapView1.Initialize("MapView1")
' ensure that the map displays the Mapnik tiles
MapView1.SetTileSource("Mapnik")
' disable the data connection
MapView1.SetDataConnectionEnabled(False)

The maps are read directly from osmdroid folder and displayed on the device.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
A)

You need to use only these formats for osmdroid offline in MOBAC :
MBTiles SQLite
Osmdroid ZIP
Osmdroid GEMF
Osmdroid SQLite

SQLITE for LOCUS is different like SQLITE for osmdroid.

B)

I have not been successful to read osmdroid maps from micro SD Card.
If you find the way to read the osmdroid offline maps from micro SD Card, please share the solution with me.

Raster map files have to be in the "osmdroid" folder in the Internal (shared) storage (no micro SD card).
Create the folder with the name osmdroid in the Internal (shared) storage and copy the map files (SQLite, GEMF ....) in it.
Do not create the Mapnik subfolder. Create only osmdroid folder with the map files in it.


B4A code is somethink like this:

MapView1.Initialize("MapView1")
' ensure that the map displays the Mapnik tiles
MapView1.SetTileSource("Mapnik")
' disable the data connection
MapView1.SetDataConnectionEnabled(False)

The maps are read directly from osmdroid folder and displayed on the device.

Thanks, will have a go a this again.
Had kind of given up on using SQLite file and for now use png.tile files laid out in subfolders like this:
Computer\Galaxy S9\Phone\osmdroid\tiles\Mapnik\18\129583\85774.png.tile
This works well, but not sure about expiring files, so have made a backup on the PC.

Will let you know if I manage to access the map from the SD.

RBS
 
Upvote 0

js486dog

Active Member
Licensed User
Longtime User
Thanks, will have a go a this again.
Had kind of given up on using SQLite file and for now use png.tile files laid out in subfolders like this:
Computer\Galaxy S9\Phone\osmdroid\tiles\Mapnik\18\129583\85774.png.tile
This works well, but not sure about expiring files, so have made a backup on the PC.

Will let you know if I manage to access the map from the SD.

RBS
I think it is a little complicated to work with a lot of pure png tiles in subfolders (copy files as offline map).
I prefere to work with one zip, one sqlite, one mbtile, one gemf file as offline map.
But I work only with offline map files.
Different can be working with online and also with offline files. You can fill up the Mapnik subfolder online and use these files also offline.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
You can fill up the Mapnik subfolder online and use these files also offline.

Yes, that is what I am doing currently. For this project I only want offline map as it is a small area and little relevant will change.
Still not managed to get a map from SQLite file. Do you have a small SQLite map file that I could try?
Ideally I would like to move all those png files I have now to SQLite and get OSMDroid get the tiles from that file.
I am not sure though how this SQLite file should be constructed, so what should be the schema and the logic.

RBS
 
Upvote 0

js486dog

Active Member
Licensed User
Longtime User
Yes, that is what I am doing currently. For this project I only want offline map as it is a small area and little relevant will change.
Still not managed to get a map from SQLite file. Do you have a small SQLite map file that I could try?
Ideally I would like to move all those png files I have now to SQLite and get OSMDroid get the tiles from that file.
I am not sure though how this SQLite file should be constructed, so what should be the schema and the logic.

RBS
Look here:
https://www.b4x.com/android/forum/threads/b4a-solved-osmdroid-offline-maps-sqlitedb.86313/

There is the structure of the sqlite for osmdroid in jpg files.

The example of sqlite file for osmdroid download here:
https://ulozto.sk/!ABG1pfMwCLWJ/vrutkysql-sqlite
 
Upvote 0

js486dog

Active Member
Licensed User
Longtime User
Yes, that is what I am doing currently. For this project I only want offline map as it is a small area and little relevant will change.
Still not managed to get a map from SQLite file. Do you have a small SQLite map file that I could try?
Ideally I would like to move all those png files I have now to SQLite and get OSMDroid get the tiles from that file.
I am not sure though how this SQLite file should be constructed, so what should be the schema and the logic.

RBS
I think better is to create osmdroid zip map file (no sqlite) if you have got png files.
Look at attached pdf file - the way as do it is in the pdf file.

You can create your own maps also from MAPERITIVE by the pdf way.
 

Attachments

  • zip map file for osmdroid.pdf
    165.6 KB · Views: 435
Upvote 0

js486dog

Active Member
Licensed User
Longtime User
Thanks, will have a go a this again.
Had kind of given up on using SQLite file and for now use png.tile files laid out in subfolders like this:
Computer\Galaxy S9\Phone\osmdroid\tiles\Mapnik\18\129583\85774.png.tile
This works well, but not sure about expiring files, so have made a backup on the PC.

Will let you know if I manage to access the map from the SD.

RBS
You need to have the end of the png files for zip map file like this:
Computer\Galaxy S9\Phone\osmdroid\tiles\Mapnik\18\129583\85774.png
NO LIKE THIS:
Computer\Galaxy S9\Phone\osmdroid\tiles\Mapnik\18\129583\85774.png.tile

NO .png.tile but only .png
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I think better is to create osmdroid zip map file (no sqlite) if you have got png files.
Look at attached pdf file - the way as do it is in the pdf file.

You can create your own maps also from MAPERITIVE by the pdf way.

Thanks, will have a look at Maperitive again.

RBS
 
Upvote 0
Top