Simple offline map display

Malky

Active Member
Licensed User
Longtime User
Is there a simple 1,2 3 tutorial to get a map, save it and display it in an app offline in B4A?

If so, does anyone know roughly what size of saved file would be created for say a 50km radius map?

Cheers,

Malky
 

canalrun

Well-Known Member
Licensed User
Longtime User
Search these forums for OSMDroid. It is a library for B4A created by "warwound". He has also created many tutorials. I am sure one addresses off-line map data. I use OSMDroid with off-line data. I use a program called Maperitive to download and generate the map data files.

I am just guessing, but you might expect a 20 MB data file for a 50 km area. The data file size is very dependent on the zoom levels that are included. At higher zoom levels you get much more data.

I have a free app on Google Play called GPSTrac. at the bottom of the included help file is a very short, quick and dirty tutorial to get you started using Maperitive.

Barry.
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Thanks for that Barry, I will certainly have a look.

Not too sure about the big files though as I may need a few? I suppose to get the detail you could need then this is to be expected.

Cheers,

Malky
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
HI again, I have tried Maperitive and created the tiles, but what do I set as the tilesource in the app?

I used the

export-svg
zip zip-file=myfiles.zip

I just get a blank grid?

Cheers,

Malky
 
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
HI again, I have tried Maperitive and created the tiles, but what do I set as the tilesource in the app?
I used the
export-svg
zip zip-file=myfiles.zip
I just get a blank grid?
Cheers,
Malky

Hello,
below I've copied the text from my GPSTrac help file for creating off-line map data:

First, download and install a map creation program. You will generally create the map data on a PC (Windows, Apple, Linux, etc.) and then transfer the map data to a folder on the Android device where it can be accessed by GPSTrak. There are many free and paid map creation programs available. .The following example uses a freely available program named Maperitive; Maperitive

Suppose I am planning a trip to Tasmania. I hope to drive around the entire island and explore some of the natural areas on foot. I am concerned that I may not have cellular data access for creating maps in some of the areas I may be traveling. I would like to have map data for Tasmania stored on my Android device.

I download, install, and run Maperitive. I use a Windows based computer. Other brands of computer should follow a similar procedure.

I need to navigate to Tasmania on the displayed map. I click on the map then repeatedly press Shift-Minus to zoom out displaying a larger geographic area.

Scrolling to the East, locate Tasmania to the south of Australia. With the zoom level adjusted (use Shift-Minus and Shift-Plus) so that the entire country is displayed on the map, right-click with the mouse pointer over Tasmania on the map and select: "Place Geometry Bounds Here". Adjust the resulting box to cover the area of Tasmania that is of interest.

The next step is to to actually create the map data. First, be sure the format is correct. "Web map (OSM Mapnik)" should be displayed in the bottom right-hand corner of Maperitive within the "Map Sources" tab window.

Map data is stored as "tiles". Each tile represents a small square of the map. The tiles are provided for each zoom level. You want to create tiles for an area for each zoom level that you expect to use. But, more zoom levels require more data to be stored. For larger geographic areas, you may want to limit the data to lower zoom levels and reserve the higher zoom levels for smaller regions of interest. Each zoom level requires approximately 4 times as many tiles as the previous zoom level. The amount of data can become huge very quickly.

At the bottom of the Maperitive window you'll see a text field labeled "Command Prompt". In the text field enter the command: "generate-tiles minzoom=5 maxzoom=16" (without the quotes). This will generate map data for the outlined area for the zoom levels 5 through 16. Entering the command in the Command Prompt allows us to specify the minimum and maximum zooms. If you scroll the Commander window back a little bit you will see a line similar to "Started generating tiles into directory C:\Program Files (x86)\Maperitive\Tiles". This tells you the folder where the map data will be located.

It may take a while. When complete, "Done" is displayed in the Commander window.

The map data needs to be placed into a folder with the same name as the data source (see the Map Data Source setting above). The data collected here is from a map source named "Mapnik".

Navigate to the folder where the map tiles where saved (In Explorer in Windows. My tiles are saved in the folder C:\Program Files (x86)\Maperitive\Tiles). Create a directory named "Mapnik". You will see folders named "5", "6", "7",..., "16". Move these folders into the "Mapnik" folder. Now create a zip file named Tas.zip. Add the "Mapnik" folder to Tas.zip. (The name of the file is not important as long as the extension is ".zip").

Now Tas.zip needs to be copied to your Android device. I use FTP, but many devices provide a way to connect the device to your PC. Navigate to the folder on the Android device for map data. On my devices this folder is named: "/mnt/sdcard/osmdroid/", but this may be slightly different on each device. You may have to search around a bit. Transfer the Tas.zip file to the "osmdroid" folder on your device.

The data format I use is: OSM Mapnik.
Within the zip file the tile directories should be stored within a directory named Mapnik.

Barry.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
I am just guessing, but you might expect a 20 MB data file for a 50 km area. The data file size is very dependent on the zoom levels that are included. At higher zoom levels you get much more data.

Look at the size of the county of Norfolk, UK: https://maps.google.co.uk/?q=norfolk+uk

Now look at this APK: http://android.martinpearman.co.uk/b4a/temp/MapsForgeDemo.apk - i compiled that in B4A just a few minutes ago.
It's 4.7MBs and contains offline maps for zoom levels 0 to 21 for the entire county of Norfolk.
This is a vector based mapping library, raw Open Street Map data is converted into a map database and the device renders it's own raster tiles from the vector data - on the fly.

You can read more about the mapsforge library here: mapsforge - free mapping and navigation tools - Google Project Hosting.
If you have time you could install the official android mapsforge demo app (AdvancedMapViewer): Downloads - mapsforge - free mapping and navigation tools - Google Project Hosting
The advanced map viewer allows you to view online (raster) tiles or offline vector based tiles.
Now browse the available map databases: Index of /maps.
You can download any of the available map databases, transfer them to your device and load them in the AdvancedMapViewer.
That'll give you an idea of how much or how little data is required to cover an area.

Mapsforge isn't perfect, it has some bugs (see how it fails to render the sea as blue around Norfolk?).
Currently the mapsforge developers are hoping to release a new version that has many new features and has been rewritten to elimate many of the old bugs.
There's no knowing when this new version will be released - it could be anytime and it could be weeks.
I'm hoping to create a B4A library when the new version is released, the Norfolk APK was compiled using a B4A mapforge library that i created based on an old version of mapsforge that is a bit buggy and will no longer be maintained.
So i shan't be uploading this old version to the forum - hopefully the new version will be worth the wait.

Martin.
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Hi guys, I had a very brief chance to test Barry's solution last night, but when I started creating the tiles, it seemed to hang when creating zoom 12 tiles?

I tried it again, only going from zoom 5 to 11 and managed to create something that works as suggested, although I will have another test tonight to get all the tiles as I could do with zooming a bit deeper. The above file created was just over 1Mb.

I believe it's possible to add markers in real time Martin? Although I haven't had time to go fully through your expert tutorials, I hope to get some time tonight to try and get this working and integrated into my app.

Thanks very much for the input guys and very much appreciated.

I will post any findings for the benefit of other users here.

Cheers,

Malky
 
Upvote 0

Malky

Active Member
Licensed User
Longtime User
Ok, tried a few options.

Using Barry's suggested Maperative only so far:-

When I tried zoom 5 -16, my drive capacity was getting 2Gb+ less!

Tonight I tried again with a top level of 14 and still the file size (Varna in Bulgaria, which region goes way beyond the actual city) came to 21.9Mb which again seems a bit much of a download for a user?

I know I would think it worth it if it really wanted it, but not everyone has a lot of spare drive space.

I may have to offer the option to download or use Google where possible?

Anyway, thanks again guys, I'll have to think about this one.

Cheers,

Malky

[EDIT]

Sorry Martin, I didn't get anywhere with your suggestion, unless I am missing something? Do I have to download an app to the phone to get anywhere or can I do this on the PC, (preferably)?

Malky
 
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
Sorry Martin, I didn't get anywhere with your suggestion, unless I am missing something? Do I have to download an app to the phone to get anywhere or can I do this on the PC, (preferably)?

Malky

Hi there Malky.

As you've found out, a collection of map tiles for anything but a small area soon becomes massive.

My previous post documented the mapsforge library and it's use of vector databases instead of tile archives.
A vector database represents map data in a binary/digital format NOT as an image tile.
The device then turns this digital/binary data into tiles when it renders the map.

Take a look at the same link i posted: http://android.martinpearman.co.uk/b4a/temp/MapsForgeDemo.apk
I have now recompiled that app so that it contains a map database which covers the area 25.86, 42.77, 28.88, 44.02 (that's minimum latitude, minimum longitude, maximum latitude, maximum longitude).
It's just 4.55MBs in size and covers the area around Varna from zoom levels 0 to 21.
BUT the mapsforge library currently has a bug where it doesn't proeprly render the sea as blue!
I'm hoping that when the new version of mapsforge is released that this bug will be fixed - it makes using the map in an area that displays the sea look awful.

Vector based maps are the only real solution for offline maps - you can cover a massive area with a relatively small database.
I haven't made my b4a mapsforge wrapper library generally available and don't intend to - i don't have the time to document it and provide technical support let alone deal with feature requests.

If you want to try mapsforge and can handle the incorrectly rendered sea areas then send me a PM and i'll send you a link so you can download it.

Martin.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
That's looks promising.
Shame it's a not a simple one step solution, i'll try and find time to test it over the next week.

Martin.
 
Upvote 0
Top