Android Tutorial OSMDroid - MapView for B4A tutorial

You can find the OSMDroid library thread here: http://www.b4x.com/forum/additional...tes/16309-osmdroid-mapview-b4a.html#post92643.

AIM: Create and initialize a MapView, enable the map zoom controller and multitouch controller, set a zoom level then center the map on a location.

B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim MapView1 As MapView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   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
      Log("WARNING NO EXTERNAL STORAGE AVAILABLE")
   End If
   
   '   no EventName is required as we don't need to listen for MapView events
   MapView1.Initialize("")
   Activity.AddView(MapView1, 0, 0, 100%x, 100%y)
   
   '   by default the map will zoom in on a double tap and also be draggable - no other user interface features are enabled
   
   '   enable the built in zoom controller - the map can now be zoomed in and out
   MapView1.SetZoomEnabled(True)
   
   '   enable the built in multi touch controller - the map can now be 'pinch zoomed'
   MapView1.SetMultiTouchEnabled(True)
   
   '   set the zoom level BEFORE the center (otherwise unpredictable map center may be set)
   MapView1.Zoom=14
   MapView1.SetCenter(52.75192, 0.40505)
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

The code is pretty self-explanatory.

I've added the code to check if the device has available external storage as OSMDroid will not display any tiles if no external storage is available.
External storage is used to save/cache all downloaded tiles - no external storage means no map!
(I'll omit that check from future tutorials but it's something to bear in mind - not that i know of any Android devices that have no external storage).

Create and initialize a MapView, add it to the Activity 100% width and 100% height.
Enable the zoom and multi-touch controller.
Zoom in to level 14 then set the MapView center to a location (sunny Norfolk, UK!).

I've found that setting the map center and then immediately setting the zoom level does not work as expected.
I think that while the MapView is setting the map center it also zooms in so the end result is unpredictable.

Pan and zoom the map, now rotate your device and you'll see the map returns to it's initial state of zoom level 14, center (52.75192, 0.40505).

I shall show you how to save and restore the MapView state next...

Martin.
 

Attachments

  • 01 - SimpleMap.zip
    5.8 KB · Views: 4,638
Last edited:

warwound

Expert
Licensed User
Longtime User
Hi Martin,
on which place do I have to paste this code?

You'd have to convert that java code to b4a in order to use it.
Far easier to enable and disable hardware acceleration in the manifest.

Search the forum and you'll find examples setting hardware acceleration in the manifest.

Martin.
 
  • Like
Reactions: TAK

TAK

Member
Licensed User
Longtime User
Hi Martin,
is it possible to save the path where i move? For example like Google Maps with a color line?

Thx
 

Attachments

  • Path.PNG
    Path.PNG
    474.4 KB · Views: 547

TAK

Member
Licensed User
Longtime User
Hi Martin,
is it possible to save the path where i move? For example like Google Maps with a color line?

Thx

where is the mistake in the Code? I think Latitude and Latitude are wrong.

thx
B4X:
Sub Process_Globals
End Sub

Sub Globals
    Dim MapView1 As MapView
    Dim PathOverlay1 As PathOverlay
    Dim TouchEventsOverlay1 As TouchEventsOverlay
    Dim GeoPoint1 As GeoPoint
    Dim GPS1 As GPS
End Sub

Sub Activity_Create(FirstTime As Boolean)
    MapView1.Initialize("")
    MapView1.SetMultiTouchEnabled(True)
    MapView1.SetZoomEnabled(True)
    Activity.AddView(MapView1, 0, 0, 100%x, 100%y)
   
    MapView1.Zoom=14
    MapView1.SetCenter(47.46916, 8.48367)
   
    PathOverlay1.Initialize(MapView1, Colors.Red)
    PathOverlay1.StrokeWidth=4dip
    MapView1.AddOverlay(PathOverlay1)
   
    TouchEventsOverlay1.Initialize("TouchEventsOverlay1")
    MapView1.AddOverlay(TouchEventsOverlay1)
   
   
    GeoPoint1.Initialize(0, 0)
        If FirstTime Then
       
        GPS1.Initialize("GPS")
       
        End If
End Sub

Sub Activity_Resume
GPS1.Start(1,1) 'Listen to GPS with no filters.
End Sub

Sub Activity_Pause (UserClosed As Boolean)
GPS1.Stop
End Sub

Sub GPS_LocationChanged (Location1 As Location)
    GeoPoint1.Latitude = Location1.Latitude
    Log(Location1.Latitude)
    GeoPoint1.Longitude = Location1.Longitude
    Log(Location1.Longitude)
    PathOverlay1.AddPoint3(GeoPoint1)
    MapView1.Invalidate
   
   
End Sub
 

warwound

Expert
Licensed User
Longtime User
What do you see on your map and in the log when you run your program?

Can you upload a working b4a project that i can run and debug myself?
 

TAK

Member
Licensed User
Longtime User
thx
the Path (red line) should follow my movement and draw a line. But it seems that the path is in Africa but i am from Europe...
 

Attachments

  • Path.zip
    6 KB · Views: 396

warwound

Expert
Licensed User
Longtime User
In your sub GPS_LocationChanged you ought to Dim a new GeoPoint object each time the sub is called.
Re-using GeoPoint1 will have unpredictable results.

Martin.
 
  • Like
Reactions: TAK

Spectre

Active Member
Licensed User
Longtime User
In your sub GPS_LocationChanged you ought to Dim a new GeoPoint object each time the sub is called.
Re-using GeoPoint1 will have unpredictable results.

Martin.


Hi Warwound ... After so long ... Any news on the development of the 4.1 that I had tried in beta?
 

rayofcumbria

Member
Licensed User
Longtime User
Hi,
I'm using osmdroid 4.1 (fantastic library :)). Has anyone successfully set the orientation so the direction pointer is pointing upwards?

big thanks in advance.
 

Spectre

Active Member
Licensed User
Longtime User
Hi!
You must use the set property map orientation...

MapView1.SetMapOrientation(degree)
 

nemiroG1

Member
Licensed User
Longtime User
Martin,
First off, thank you so much for all your hard work on this project! It is absolutely amazing!

I have two questions (as I am quite new at this).

1. Is it possible to use and/or convert Chartbundle files with OSMDroid? I am needing aviation type charts, and trying to figure out how to get them. Right now, chartbundle looks like the only way, but again, I am new at this.


2. I read your much earlier post about the black bands that sometimes appears when rotating or changing the map orientation. Has there been any progress on this front?

Thanks, again!
 

warwound

Expert
Licensed User
Longtime 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:
https://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:

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://<my tileserver url>/%3$d/%1$d/%2$d.png
Url parameters are %1$d tileX, %2$d tileY, %3$d zoom
Width - tile width in pixels.
Height - tile height in pixels.

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.
 

nemiroG1

Member
Licensed User
Longtime User
Martin,
Thank you so much for this detailed response! I will work with this here in just a little bit. I travel to the UK from time to time. Next time I do, I need to look you up, as I owe you a pint or two. In the meantime, paypal donation sent!
 

PABLO2013

Well-Known Member
Licensed User
Longtime User
OSM Binary Format
GREETINGS MARTIN
HOW I CAN USE OSM LIBRARY TO READ A MAP OSM BINARY FORMAT ... OR you indicate ME AS I DO
TKS
 

warwound

Expert
Licensed User
Longtime User
You can use the MapsForgeTileSource to display binary OSM data on an OSMDroid map as long as the OSM data is in the MapsForge format.
There's a version of the MapsForgeTileSource for OSMDroid 3.0.8 as well as a version for the newer OSMDroid 4.1.

Search the forum for MapsForgeTileSource and you'll find more info.
 

nemiroG1

Member
Licensed User
Longtime 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:
https://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.


I am needing to use this offline for now, and I have gotten it to work, although it is not perfect. I am trying to improve it all of the time. I used MOBAC to download the Chartbundle aviation sectional charts in the OSMDroid .zip format. After it was down, you need to extract the whole archive, and rename the root folder to "MapquestOSM" (exactly as shown in between the quotes). In the B4A IDE, the map tile source will need to be set to MapquestOSM to match. I put the .zip file in the /osmdroid folder on the device, and so far, it is working! Using a slightly modified version of your offline tiles code:

B4X:
Version=4.2
IconFile=
NumberOfModules=0
Build1=Default,uk.co.martinpearman.b4a.mapviewtutorial
DoNotOverwriteManifest=False
ManifestCode=
NumberOfFiles=1
File1=chartbundle.zip                   '<-----------  Change here
NumberOfLibraries=2
Library1=core
Library2=osmdroid_4_1            '<-----------  I used OSMDroid 4.1, and it all worked fine
@EndOfDesignText@
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: MapView Simple Example
    #VersionCode: 1
    #VersionName: 
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

Sub Process_Globals
    Dim MapCenter As GeoPoint
    Dim ZoomLevel As Int
End Sub

Sub Globals
    Dim MapView1 As MapView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        Dim OfflineTileCacheFilename, TileCacheDir As String
        OfflineTileCacheFilename="chartbundle.zip"                        '<-----------  Change here
        TileCacheDir=File.DirRootExternal&"/osmdroid"
        '    check if the offline tile cache has already been copied to the OSMDroid cache folder
        If File.Exists(TileCacheDir, OfflineTileCacheFilename)=False Then
            '    create the 'osmdroid' cache folder if it does not exist
            If File.Exists(TileCacheDir&"/", "")=False Then
                File.MakeDir(File.DirRootExternal, "osmdroid")
            End If
            '    copy the offline tile cache to the OSMDroid cache folder
            File.Copy(File.DirAssets, OfflineTileCacheFilename, TileCacheDir, OfflineTileCacheFilename)
            MapView1.SetUseDataConnection(False)            '<-----------  Change here
        End If
    End If
   
    MapView1.Initialize("MapView1")
    Activity.AddView(MapView1, 0, 0, 100%x, 100%y)
   
    MapView1.SetMultiTouchEnabled(True)
    MapView1.SetZoomEnabled(True)
   
    '    ensure that the map displays the Mapnik tiles
    MapView1.SetTileSource("MapquestOSM")                  '<-----------  Change here
    '    disable the data connection
    MapView1.SetDataConnectionEnabled(False)
   
    If FirstTime Then
        '    center the map within the area covered by the offline tiles
        MapCenter.Initialize(52.75192, 0.40505)
        '    choose a zoom level for which offline tiles exist
        ZoomLevel=10
    End If
   
    MapView1.GetController.SetZoom(ZoomLevel)        '<-----------  Change here
    MapView1.GetController.SetCenter(MapCenter)       '<-----------  Change here
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    MapCenter=MapView1.GetCenter                   '<-----------  Change here
    ZoomLevel=MapView1.GetZoomLevel             '<-----------  Change here
    MapView1.SetDataConnectionEnabled(False)    '<-----------  Change here
End Sub

Sub MapView1_ZoomChanged
    'If MapView1.Zoom>12 Then
    '    '    i could have set the map zoom to 12 if it was more than 12 but this way you can see the level 12 tiles stretched to display where zoom level 13+ does not exist
    '    ToastMessageShow("Tiles are cached for zoom levels 0 to 12 only, current zoom level is: "&MapView1.Zoom, False)
    MapView1.SetDataConnectionEnabled(False)                    '<-----------  Change here
    MapView1.GetController.SetCenter(52.75192, 0.40505)      '<-----------  Change here
    'End If
End Sub






Think I edited that right, but I just took your code and modified what I had to change, for the sake of this post. My problems are these:

1. I cannot seem to get an icon on the map, showing my location. The map comes up, and it moves all the right ways, just no reference point.

2. I cannot seem to display the scale bar. I have tried several iterations, and no joy. Both this and #1 worked in 3.0.8

3. Is there a way to move the "pivot point" and hence my actual location to the bottom of the screen, so that more of the map is visible "in front of me"? The reason I ask is that I am trying to do something aviation related here, and since airplanes cannot back up, what is in front of me is much more important than anything behind me. As a result, seeing a third or half a screen more of what is in front of me is pretty useful.

4. Is there a way to allow me to manually pan the map (Which I can do), but set a delay for how long it will be until the map tries to update and re-center? This would be handy when you are trying to look at something, and get more than a second to look at the map, before it tries to slew back to the GPS coordinate.

Snips from my code below:

B4X:
Sub Process Globals
    Dim InitialTileSourceName As String = "MapquestOSM"
    Dim SelectedTileSource As OSMDroid_TileSource
    Dim CurrentGeoPoint As OSMDroid_GeoPoint

    Dim MapView1 As OSMDroid_MapView
    Dim MinimapOverlay1 As OSMDroid_MinimapOverlay
    Dim ScaleBarOverlay1 As OSMDroid_ScaleBarOverlay
    Dim TileSourceSpinner As Spinner
    Dim MapOrientation As Int
    Dim TileSourceFactory1 As OSMDroid_TileSourceFactory

    '   create some variables to save the MyLocationOverlay state
    Dim CompassEnabled, FollowLocationEnabled, MyLocationEnabled As Boolean
End Sub

Sub Globals   
    Dim MapView1 As OSMDroid_MapView
    Dim MinimapOverlay1 As OSMDroid_MinimapOverlay
    Dim ScaleBarOverlay1 As OSMDroid_ScaleBarOverlay
    Dim TileSourceSpinner As Spinner
    Dim MapOrientation As Int
    Dim TileSourceFactory1 As OSMDroid_TileSourceFactory
      '   create the MyLocationOverlay
    Dim MyLocationOverlay1 As OSMDroid_MyLocationOverlay
End Sub


Sub Activity_Create(FirstTime As Boolean)
    Dim TileSourceFactory1 As OSMDroid_TileSourceFactory
    Dim AvailableTileSources() As OSMDroid_TileSource


    TileSourceSpinner.Initialize("TileSourceSelect")    'Spinner on settings panel for selecting where map tiles are coming from


    '------- Set up the map view ----------------------   
    '   no EventName is required as we don't need to listen for MapView events
    MapView1.Initialize("")
    MapPanel.AddView(MapView1, 0, 0, MapPanel.Width, MapPanel.Height)
    '   initialize and add the MyLocationOverlay to the MapView, an EventName is used as we'll be listening for all three events that this overlay generates
    MyLocationOverlay1.Initialize("MyLocationOverlay1", MapView1)
    '   enable the built in zoom controller - the map can now be zoomed in and out
    MapView1.SetBuiltInZoomControls(True)     
    '   enable the built in multi touch controller - the map can now be 'pinch zoomed'
    MapView1.SetMultiTouchControls(True)
    '---------------------------------------------------

   If FirstTime Then
        '-------- Setup Map View and Cached Map Tile Files --
        Dim OfflineTileCacheFilename, TileCacheDir As String
        OfflineTileCacheFilename="chartbundle.zip"
        TileCacheDir=File.DirRootExternal&"/osmdroid"
        '    check if the offline tile cache has already been copied to the OSMDroid cache folder
        If File.Exists(TileCacheDir, OfflineTileCacheFilename)=False Then
            '    create the 'osmdroid' cache folder if it does not exist
            If File.Exists(TileCacheDir&"/", "")=False Then
                File.MakeDir(File.DirRootExternal, "osmdroid")
            End If
            '    copy the offline tile cache to the OSMDroid cache folder
            File.Copy(File.DirAssets, OfflineTileCacheFilename, TileCacheDir, OfflineTileCacheFilename)
        End If

        '   by default the map will zoom in on a double tap and also be draggable - no other user interface features are enabled
        '   set the zoom level BEFORE the center (otherwise unpredictable map center may be set)
        MapCenter.Initialize(0.0, 0.0)        'Center to start off the app
        MapView1.GetController.SetZoom(9)        'Set the initial zoom to 9

        SelectedTileSource = TileSourceFactory1.GetTileSource(InitialTileSourceName)

        MapView1.SetMapOrientation(0)    'Initially set the map up to not rotate, but face north (0°)
  End If



'....snip....
'After setting up GPS and other items, I put this in

    '   ensure that the MinimapOverlay is the LAST overlay added to the MapView
    MinimapOverlay1.Initialize(MapView1)                         '<-------------This works fine
    MinimapOverlay1.Enabled = True
    MapView1.GetOverlays.Add(MinimapOverlay1)
    cbMiniMap.Checked = True            'ensure that the checkbox for mini map display is already checked
   
    ScaleBarOverlay1.Initialize            '<--------------- This is NOT working (worked with OSMDroid 3.0.8)
    ScaleBarOverlay1.SetNautical
    ScaleBarOverlay1.Enabled = True
    MapView1.GetOverlays.Add(ScaleBarOverlay1)
    cbScaleBar.Checked = True            'ensure that the checkbox for scale bar is already checked

  '    CompassEnabled = MyLocationOverlay1.CompassEnabled    '<---------- Commented out, as it causes errors.  Worked in OSMDroid 3.0.8
    cbCompass.Checked = False

    MyLocationOverlay1.EnableFollowLocation             '<---------- This works fine
    cbFollowLocation.Checked = True
   
    MyLocationOverlay1.EnableMyLocation                 '<----------- Cannot see an icon for my 'person'  Worked in OSMDroid 3.0.8
    cbMyLocation.Checked = True
   
    MapView1.SetUseDataConnection(False)               '<---------- This works fine
    cbUseOfflineMaps.Checked = True
End Sub

Sub Activity Resume
    If GPS1.GPSEnabled = False Then
        ToastMessageShow("Please enable the GPS device.", True)
        StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
    Else
        GPS1.Start(0, 0) 'Listen to GPS with no filters.
    End If
End Sub


Sub Activity_Pause (UserClosed As Boolean)
    MapCenter=MapView1.GetMapCenter
    TileSource=MapView1.GetTileProvider
    ZoomLevel=MapView1.GetZoomLevel
   
    '   save the MyLocationOverlay state
 '   CompassEnabled=MyLocationOverlay1.CompassEnabled
      FollowLocationEnabled = MyLocationOverlay1.IsFollowLocationEnabled
    MyLocationEnabled = MyLocationOverlay1.IsMyLocationEnabled
End Sub


'
' **********************************************************************************************************************************************
' *****************  APP Settings SECTION ******************************************************************************************************
' **********************************************************************************************************************************************
'
Sub cbMyLocation_CheckedChange(Checked As Boolean)                 '<---------NOT working in OSMDroid 4.1
    If Checked = True Then
        MyLocationOverlay1.EnableMyLocation
    Else
        MyLocationOverlay1.DisableMyLocation
    End If   
End Sub


Sub cbFollowLocation_CheckedChange(Checked As Boolean)        '<---------- Working fine in OSMDroid 4.1
    If Checked = True Then
        MyLocationOverlay1.EnableFollowLocation
    Else
        MyLocationOverlay1.DisableFollowLocation
    End If
End Sub


Sub cbCompass_CheckedChange(Checked As Boolean)
 '   MyLocationOverlay1.CompassEnabled=Not(MyLocationOverlay1.CompassEnabled)   '<---------NOT working in OSMDroid 4.1
End Sub

Sub cbScaleBar_CheckedChange(Checked As Boolean)              '<---------NOT working in OSMDroid 4.1
    If Checked = True Then
        ScaleBarOverlay1.Enabled = True
    Else
        ScaleBarOverlay1.Enabled = False   
    End If
End Sub

Sub cbMiniMap_CheckedChange(Checked As Boolean)          '<---------- Working fine in OSMDroid 4.1
    If Checked = True Then
        MinimapOverlay1.Enabled = True
    Else
        MinimapOverlay1.Enabled = False   
    End If   
End Sub

Sub cbRotateMap_CheckedChange(Checked As Boolean)     '<---------- Working fine in OSMDroid 4.1
    If Checked = True Then
        MapView1.SetMapOrientation(360 - CurrentGPSBearing)  'Sets map orientation by whatever the GPS bearing is
    Else
        MapView1.SetMapOrientation(0)  'Sets map orientation to face north (0°)
    End If   
End Sub

Sub cbCenterOnLocation_CheckedChange(Checked As Boolean)     '<---------- Working fine in OSMDroid 4.1
    If Checked = True Then
        MapView1.GetController.SetCenter(CurrentGeoPoint)
    Else

    End If
End Sub

Sub cbUseOfflineMaps_CheckedChange(Checked As Boolean)    '<---------- Working fine in OSMDroid 4.1
    If Checked = True Then
        MapView1.SetUseDataConnection(False)
    Else
        MapView1.SetUseDataConnection(True)
    End If   
End Sub

Sub TileSourceSpinner_ItemClick (Position As Int, Value As Object)         '<---------- Working fine in OSMDroid 4.1
'    TileSourceSpinner.SelectedIndex=TileSourceSpinner.IndexOf(TileSource)
    'set the MapView Tile Source
    'TileSourceName = Value
    SelectedTileSource = TileSourceFactory1.GetTileSource(Value)
    MapView1.SetTileSource(SelectedTileSource)
End Sub
' **********************************************************************************************************************************************


Any help you can lend will be most appreciated. Thanks!
 

nemiroG1

Member
Licensed User
Longtime User
Martin,
OK, I finally managed to try the URLTileSource for OSMDroid 4.1, and taking that, and combining it with the XML data you posted above worked straight off! Thank you! For reference, here is the code (not that it is hard to figure out) to use aviation sectional maps (US Only at this time):

B4X:
Version=4.2
IconFile=
NumberOfModules=0
Build1=Default,uk.co.martinpearman.b4a.osmdroiddemo
DoNotOverwriteManifest=False
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>~\n~<supports-screens android:largeScreens="true" ~\n~    android:normalScreens="true" ~\n~    android:smallScreens="true" ~\n~    android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~'End of default text.~\n~~\n~'    required for ScaleBarOverlay?~\n~SetApplicationAttribute(android:hardwareAccelerated, "false")
NumberOfFiles=0
NumberOfLibraries=2
Library1=core
Library2=osmdroid_4_1
@EndOfDesignText@
#Region  Project Attributes 
    #ApplicationLabel: OSMDroid demo
    #VersionCode: 1
    #VersionName: 
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
    #FullScreen: True
    #IncludeTitle: False
#End Region

Sub Process_Globals
    Dim Constants1 As OSMDroid_Constants
End Sub

Sub Globals
    Dim InitialGeoPoint As OSMDroid_GeoPoint
    Dim MapView1 As OSMDroid_MapView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    '    check the manifest for edits made re hardware acceleration
   
    MapView1.Initialize("")
   
    Dim MyTileSourceName As String="MyTileSourceName"
    Dim TileSourceFactory1 As OSMDroid_TileSourceFactory
    If Not(TileSourceFactory1.ContainsTileSource(MyTileSourceName)) Then
        Dim MyTileSource As OSMDroid_UrlTileSource
        MyTileSource.Initialize(MapView1, MyTileSourceName, "http://wms.chartbundle.com/tms/v1.0/sec/%3$d/%1$d/%2$d.png?type=google", 0, 16, 256)
        TileSourceFactory1.AddTileSource(MyTileSource)
    End If
   
    MapView1.SetTileSource(TileSourceFactory1.GetTileSource(MyTileSourceName))
   
    MapView1.GetOverlayManager.GetTilesOverlay.SetLoadingBackgroundColor(Colors.Green)
    MapView1.GetOverlayManager.GetTilesOverlay.SetLoadingLineColor(Colors.Red)
    MapView1.SetBuiltInZoomControls(True)
    MapView1.SetMultiTouchControls(True)
   
    '    now set the initial view
    '    set the zoom before the center
    InitialGeoPoint.Initialize(52.75240, 0.4040)
    MapView1.GetController.SetZoom(12)
    MapView1.GetController.SetCenter(InitialGeoPoint)
   
    Activity.AddView(MapView1, 0,0, 100%x, 100%y)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 
Top