Android Tutorial OSMDroid - MapView for B4A tutorial

entolium

Member
Licensed User
Hello,

I'm running all examples with overlay and always get the same error. Png not found (/resorces/org/osmdroid/...). I'm searching, reading many posts and tried hundreds of things, but is impossible, always the same error. I'm desperate.
Is possible to copy all pngs in my device? where?

Thanks a million!!!
 

Spectre

Active Member
Licensed User
Hi!
I do not remember how it fits an personal icon that in Maylocation overlay,
instead of the triangle of direction...
 

Spectre

Active Member
Licensed User
Look here: http://www.chartbundle.com/charts/
Scroll to the section named 'Mobile Atlas Creator(MOBAC)'.

You can use MOBAC to download the ChartBundle tiles on a computer and create an offline tile archive.
You can then use this offline tile archive with OSMDroid.
Look at this forum search for more info on using MOBAC:
http://www.b4x.com/android/forum/pages/results/?query=mobac&page=1&prefix=0

An offline tile archive has a few disadvantages:
  • Covering anything but a small area will result in a large (or very large) tile archive.
    Including a large tile archive with your compiled .apk is generally impractical.
    So you then need to host the tile archive online and download it to your b4a application once the application is installed.
  • If the Chartbundle data changes then your offline tiles will be out of date and display old and/or invalid data.
    You need to monitor the Chartbundle data and be sure to update your offline tile archive whenever the Chartbundle data is changed.

The Chartbundle page (linked to above) offers for download various .xml files that can be used to configure MOBAC.
Look at this one, 'Sectional Charts':

B4X:
<?xml version="1.0" encoding="UTF-8"?>
<customMapSource>
<name>Chartbundle US Sectional Charts</name>
<minZoom>4</minZoom>
<maxZoom>13</maxZoom>
<tileType>png</tileType>
<tileUpdate>None</tileUpdate>
<url>http://wms.chartbundle.com/tms/v1.0/sec/{$z}/{$x}/{$y}.png?type=google</url>
<backgroundColor>#000000</backgroundColor>
</customMapSource>
This xml tells MOBAC all it needs to know in order for it to connect to and download tiles from this tile server.
Version 4.1 of my b4a OSMDroid library has an object named OSMDroid_UrlTileSource that's used to display tiles from an online tile server.
The OSMDroid_UrlTileSource object's Initialize method is documented:



So i'm thinking that you might be able to use OSMDroid version 4.1 and it's UrlTileSource.
Get the urls of the tile servers from the various MOBAC xml configuration files and try those urls with the UrlTileSource.
With a bit of luck it'll work perfectly and display tiles on the map with no need for an offline tile archive.

Version 4.1 of OSMDroid was never properly uploaded to the forum, it's available for download from my server here:
http://b4a.martinpearman.co.uk/osmdroid/
That link should show some version 4.1 examples available to download and one example is OSMDroid_4.1_UrlTileSource.zip which you should find useful.

Version 4.1 also has better support for map rotation - i'm not sure if the problem with blank areas appearing was fixed or not.


Very nice .. I'm sorry but I did not understand how it should be the structure of the server hosting the tiles of the map!!
 

warwound

Expert
Licensed User
Very nice .. I'm sorry but I did not understand how it should be the structure of the server hosting the tiles of the map!!
I'm not sure i understand.
Are you hoping to bulk download the chartbundle tiles then host them on a server - then display them on an OSMDroid map using UrlTileSource?
The parameters to initialize the UrlTileSource depend entirely on the location of the tiles on your server.
 

Spectre

Active Member
Licensed User
I'm not sure i understand.
Are you hoping to bulk download the chartbundle tiles then host them on a server - then display them on an OSMDroid map using UrlTileSource?
The parameters to initialize the UrlTileSource depend entirely on the location of the tiles on your server.
HI! sorry my English...

I would like to load the map on my server and then distribute it to the apk.

Use as you said OSMDroid_UrlTileSource.

But I have not figured out how to be the folder structure that I have to put on the server.

To generate the tile use MapTiler (http://www.maptiler.com/).

http://www.Myserver/MAyMAps/10
11
12
10,11,12 is folder on tile png
 

warwound

Expert
Licensed User
Read about slippy map tile naming.
This is a common way to structure and name tiles on a server.

Now look at the UrlTileSource demo:

B4X:
Dim MyTileSource As OSMDroid_UrlTileSource
MyTileSource.Initialize(MapView1, MyTileSourceName, "http://a.tile2.opencyclemap.org/transport/%3$d/%1$d/%2$d.png", 0, 16, 256)
Finally the documentation for the UrlTileSource Initialize method:

Initialize (MapView1 As MapView, TileSourceName As String, UrlTemplate As String, MinZoomLevel As Int, MaxZoomLevel As Int, TileSizePixels As Int)
Initialize the UrlTileSource.
UrlTemplate - a String which is the Url to a tile with X, Y and zoom parameters replaced:
Here the standard OSM slippy map tilenaming is used.
http:///<domain>/%3$d/%1$d/%2$d.png Url parameters are %1$d tileX, %2$d tileY, %3$d zoom
Does MapTiler save your tiles in a folder structure that's identical to the slippy map tile naming scheme?
 

Spectre

Active Member
Licensed User
Ok perfect , the problem was simply in the wrong folder structure ... Thanks Warwound... PS how it fitsan personal icon that in Maylocation overlay,
instead of the triangle of direction... ?
 

warwound

Expert
Licensed User
PS how it fitsan personal icon that in Maylocation overlay,
instead of the triangle of direction... ?
There's no built in method to change the MyLocation overlay icon.
If you open the library file OSMDroid_4_1.jar with WinRAR or another archive manager and look in the folder /org/osmdroid/ you'll see the various built in icons used by the library.
direction_arrow.png is the icon used by MyLocation.
So if you replace direction_arrow.png in the library .jar file you should see your new icon on your map.

It's not an ideal solution but it is currently the only solution.
 

Spectre

Active Member
Licensed User
B4X:
Dim MyTileSourceName As String="HikeBike"
    Dim TileSourceFactory1 As OSMDroid_TileSourceFactory
        Dim MyTileSource As OSMDroid_UrlTileSource
        MyTileSource.Initialize(MapView1, MyTileSourceName, "http://a.tiles.wmflabs.org/hikebike/%3$d/%1$d/%2$d.png",0, 17, 256)
        TileSourceFactory1.AddTileSource(MyTileSource)
 
Last edited:

Spectre

Active Member
Licensed User
They will " melt " together the two tile to get the nuances altimeter overlaid on the map??

ikebikemap
By end of August 2014, the Wikimedia Toolserver will cease operation. This means you will need to get the tiles from a different location, which is

http://{a,b,c}.tiles.wmflabs.org/hikebike/{z}/{x}/{y}.png

Example: http://a.tiles.wmflabs.org/hikebike/12/2208/1372.png

These tiles will look slightly different than the old ones but are hopefully missing no important features.

hillshading
By end of August 2014, the Wikimedia Toolserver will cease operation. This means you will need to get the hillshading tiles from a different location, which is

http://{a,b,c}.tiles.wmflabs.org/hillshading/{z}/{x}/{y}.png

Example: http://a.tiles.wmflabs.org/hillshading/12/2208/1372.png

These tiles are unchanged from the ones that were hosted on the Wikimedia Toolserver.
 

jndaniels1

Member
Licensed User
Greetings Warwound, Spectre
(And other osm guru's)


Does offline tile caching work in the same manner as in the previous v3 library? Creating a osmdroid.zip or osmdroid.sqlite tile cache with
MOBAC and placing it in the ext stroage /osmdroid ??

I hope this isn't a repeated question; I did search before posting.

I got both zip and sqlite working successfully with the previous warwound code example "11 - OfflineMaps" using sqlite (with pretty much ease).
Zip Vs Sqlite .. Sqlite is way faster!


Thanks warwound for a awesome library! And all who help!

Kind Regards
J Daniels
 

warwound

Expert
Licensed User
Does offline tile caching work in the same manner as in the previous v3 library?
Yes there's no difference in operation between v3.0.8 and v4.1.
There's syntax differences between the 2 versions but the underlying features remain unchanged.
 

anglia

Member
Licensed User
I'm fairly new to B4a and I'm very interested in the excellent work Martin has done developing this library.
I've read most of the posts in this thread, but I'm having trouble understanding the use of offline maps for 'non-geographical' applications.

Back in post #12, Martin mentioned that the library could possibly be used for circuit diagrams, floor plans etc.
I've got a large chart which I have cut into 800 png tiles (40x20 each 256x256 pixels).

I am reasonably familiar with the way that the zoom factor and 'slippy tiles' work, but I can't see how to use them as there are no geopoints, latitudes, longitudes involved.
Could someone point me in the right direction please?

Thanks
 

warwound

Expert
Licensed User
@anglia

Displaying a non geographical image in a MapView and then referencing cartesian (x, y) coordinates on the image requires you to be able to convert those cartesian coordinates into geographical (latitude, longitude) coordinates and vice versa.

OSMDroid uses the WGS84 geographical coordinate system.

Which version of OSMDroid are you using?
There are 2 versions available: 3.0.8 and 4.1.
I never had time to properly upload version 4.1 to the forum but it is available from my website: http://b4a.martinpearman.co.uk/osmdroid/.

To convert between cartesian and geographical coordinates you need to use the OSMDroid Projection object.
The Projection object was never included in version 3.0.8 but is included in version 4.1.
Look at this page: http://b4a.martinpearman.co.uk/osmdroid/OSMDroid_4_1.html, search the page for OSMDroid_Projection and you'll see there are various methods to make these coordinate conversions.
 

anglia

Member
Licensed User
Thanks Warwound.

I'll look into the OSMDroid Projection object and give it a go.

I'm using version 3.0.8 (v 3.52). I know that version is 4.1 is available and I have downloaded it (version 4.1 (0.04) and tried to use it . However, when I use v4.1 and try to compile your example code for '11 - Offline mapsupdated' - (post #12 of this thread), I get the following error message-

B4A version: 5.20
Parsing code. Error
Error parsing program.
Error description: Unknown type: geopoint
Are you missing a library reference?
Occurred on line: 12 (Main)
Dim MapCenter As GeoPoint

If I go back to using version 3.08, the code compiles and runs ok.

Have I missed some modification I need to make so that I can use v4?

Thanks again
 

warwound

Expert
Licensed User
@anglia

The object names in version 4.1 are all prefixed with OSMDroid_.
Version 3.0.8's GeoPoint object is named OSMDroid_GeoPoint in version 4.1.
 
Top