Android Question OSMDroid doesn't show map

Wosl

Member
Dear All,

I try to get up and running the tutorial examples by warwound from 2012 (https://www.b4x.com/android/forum/threads/osmdroid-mapview-for-b4a-tutorial.16310/#content) but with no success. I assume I'm missing some essential part.

What happens?
I ran the first example SimpleMap01 and the result is just the grid without any map. No error/warning message appears. The same results come up with the other examples, too.

What I'm using:
- Lib OSMDroid_3_0_8 version 3.60
- targetSdkVersion="27"
- add RuntimePermissions to ensure external storage is available (see code, File.ExternalWritable result is True)
- add a user agent for httprequest (with no changes at all)
- add some permissions in the manifest (see below)

For documentation here is the code
SimpleMap01:
Sub Globals
    Dim MapView1 As MapView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult(Permission As String, Result 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("")
    MapView1.SetHttpRequestUserAgent("SimpleMap01")
    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.5179, 13.4050)        ' City of Berlin
    
    Log("All Done")
End Sub

and here is the manifest
Manifest to SimpleMap01:
AddManifestText(
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="27"/>
    <supports-screens android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:anyDensity="true"/>
    )
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")

Any idea what's missing or wrong? Any suggestion is appreciated.

Wosl
 

Wosl

Member
The reason for not displaying tiles seems to be that the write permission was not granted. The statement "File.ExternalWritable" results always to True and doesn't help.

The solution is to add
B4X:
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Now it works as expected and the maps are showing up.

Wosl
 
Upvote 0
Top