Android Question B4a osmdroid and mbtiles

Rudolf Wolf

New Member
Licensed User
Hi, i am a newbie. I try to implement a simple map view in my app using osmdroid.
I went through the tutorial
I tried for days to get maps. GmapCatcher mobac aso. Most of that stuff is blocked by the servers.
Others i dont catch cause of my poor experience.
I only found mbtyles available. After days of tryals to find a matching tutorial, i come up to you guys.
I am using OSMDroid_3_0_8_v3.60 and b4a 9.5.
Has someone a link for me or can help me to make mbtiles working in OSMDroid ?
I will give a donation for implementing a working code.
My Email

dus.mbtiles from MapTiler is in dir osmdroid on the phone
No Warnings, no Compiler errors.
I get a blank screen.

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

#Region activity Attributes
'#Region activityModule Attributes
    #FullScreen: False
    #IncludeTitle: True
    '#ApplicationLabel: GPS
    '#VersionCode: 1
    '#SupportedOrientations: unspecified
#End Region
'#BridgeLogger: true
Sub Process_Globals
    Dim MapCenter As GeoPoint
    Dim ZoomLevel As Int
End Sub

Sub Globals
'    Dim lblLon As Label
'    Dim lblLat As Label
'    Dim lblSpeed As Label
'    Dim lblSatellites As Label
    Dim MapView1 As MapView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        Dim OfflineTileCacheFilename, TileCacheDir As String
        '    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
    End If
    Activity.AddView(MapView1, 0, 0, 100%x, 100%y)
    '    ensure that the map displays the Mapnik tiles
    '    disable the data connection
    If FirstTime Then
        MapCenter.Initialize(51.2277411, 6.7734556)
        'MapCenter.Initialize(51.209142, 6.606045)
        '    choose a zoom level for which offline tiles exist
    End If
End Sub

Sub Activity_Resume
    If Starter.GPS1.GPSEnabled = False Then
        ToastMessageShow("Please enable the GPS device.", True)
        StartActivity(Starter.GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        If Result Then CallSubDelayed(Starter, "StartGPS")
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    CallSubDelayed(Starter, "StopGPS")
End Sub

Public Sub GpsStatus (Satellites As List)
    Dim sb As StringBuilder
    For i = 0 To Satellites.Size - 1
        Dim Satellite As GPSSatellite = Satellites.Get(i)
        sb.Append(CRLF).Append(Satellite.Prn).Append($" $1.2{Satellite.Snr}"$).Append(" ").Append(Satellite.UsedInFix)
        sb.Append(" ").Append($" $1.2{Satellite.Azimuth}"$).Append($" $1.2{Satellite.Elevation}"$)
    'lblSatellites.Text = sb.ToString
End Sub

Public Sub LocationChanged(Location1 As Location)
    'MapCenter.Initialize( 51.198537, 6.570160)
'    lblLat.Text = "Lat = " & Location1.Latitude
'    lblLon.Text = "Lon = " & Location1.Longitude
'    lblSpeed.Text = $"Speed = $1.2{Location1.Speed} m/s "$
'    Msgbox(Location1.Latitude, Location1.Longitude)
'    MapView1.SendToBack
'    MapView1.SetCenter(Location1.Latitude,Location1.Longitude)
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)
    End If
End Sub