Android Question OSMDroid, not showing map

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Went through the tutorial project, SimpleMap and copied that code:
https://www.b4x.com/android/forum/threads/osmdroid-mapview-for-b4a-tutorial.16310/
Have installed OSMDroids_3_0_8 version 3.60. The posted example project works fine, but can't get it to work in my app.

This is my code that loads the map:

B4X:
Sub ShowMap
 Dim arrCoordinates() As Double
 arrCoordinates = GetCoordinates
 General.RunLog("ShowMap, Lat: " & arrCoordinates(0) & ", Lon: " & arrCoordinates(1))
 If MapView1.IsInitialized = False Then
  MapView1.Initialize("")
  pnlMap.AddView(MapView1, 0, 0, 100%x, 100%y)
  'Sleep(2)
 End If
 '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= 18 'max zoom level?
 MapView1.SetCenter(arrCoordinates(0), arrCoordinates(1))
 GotoPanel(ePanelType.Map, False)
End Sub

GetCoordinates gets the coordinates from SQLite and these coordinates are fine.
The map background shows fine, but no map data. There are no errors. I can't see the difference with the tutorial code, other than that I added the MapView to a panel. Tried adding to activity instead,
but that gives the same result.

Any idea what could be the problem here?

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Went through the tutorial project, SimpleMap and copied that code:
https://www.b4x.com/android/forum/threads/osmdroid-mapview-for-b4a-tutorial.16310/
Have installed OSMDroids_3_0_8 version 3.60. The posted example project works fine, but can't get it to work in my app.

This is my code that loads the map:

B4X:
Sub ShowMap
 Dim arrCoordinates() As Double
 arrCoordinates = GetCoordinates
 General.RunLog("ShowMap, Lat: " & arrCoordinates(0) & ", Lon: " & arrCoordinates(1))
 If MapView1.IsInitialized = False Then
  MapView1.Initialize("")
  pnlMap.AddView(MapView1, 0, 0, 100%x, 100%y)
  'Sleep(2)
 End If
 '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= 18 'max zoom level?
 MapView1.SetCenter(arrCoordinates(0), arrCoordinates(1))
 GotoPanel(ePanelType.Map, False)
End Sub

GetCoordinates gets the coordinates from SQLite and these coordinates are fine.
The map background shows fine, but no map data. There are no errors. I can't see the difference with the tutorial code, other than that I added the MapView to a panel. Tried adding to activity instead,
but that gives the same result.

Any idea what could be the problem here?

RBS

Still not figured this out. I updated to OSMDroid_4_1 version 0.04:
http://b4a.martinpearman.co.uk/osmdroid/OSMDroid_4_1.html
but still same result.
The example project OSMDroid_v4.1_examples\20140227\OSMDroid_demo.b4a works fine
and I can't see the difference with my code.
My code is now slightly different due to moving to OSMDroid_4_1:

B4X:
Sub Globals()
Private MapView1 As OSMDroid_MapView

Sub ShowMap
 
 Dim arrCoordinates() As Double
 
 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
  General.RunLog("WARNING, NO EXTERNAL STORAGE AVAILABLE")
  Return
 End If
 
 Dim GeoPoint1 As OSMDroid_GeoPoint
 
 arrCoordinates = GetCoordinates
 General.RunLog("ShowMap, Lat: " & arrCoordinates(0) & ", Lon: " & arrCoordinates(1))

 GeoPoint1.Initialize(arrCoordinates(0), arrCoordinates(1))
 
 MapView1.Initialize("")
 MapView1.SetBuiltInZoomControls(True)
 MapView1.SetMultiTouchControls(True)

 'set the zoom before the center
 MapView1.GetController.SetZoom(14)
 MapView1.GetController.SetCenter(GeoPoint1)
 
 pnlMap.AddView(MapView1, 0,0, pnlMap.Width, pnlMap.Height)
 
 GotoPanel(ePanelType.ShowMap, False)
 
End Sub

Again, this shows the map background fine, but no map data.
I am sure I must be missing some simple, essential step somewhere, but can't see it.
Any suggestions?

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Still not figured this out. I updated to OSMDroid_4_1 version 0.04:
http://b4a.martinpearman.co.uk/osmdroid/OSMDroid_4_1.html
but still same result.
The example project OSMDroid_v4.1_examples\20140227\OSMDroid_demo.b4a works fine
and I can't see the difference with my code.
My code is now slightly different due to moving to OSMDroid_4_1:

B4X:
Sub Globals()
Private MapView1 As OSMDroid_MapView

Sub ShowMap
 
 Dim arrCoordinates() As Double
 
 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
  General.RunLog("WARNING, NO EXTERNAL STORAGE AVAILABLE")
  Return
 End If
 
 Dim GeoPoint1 As OSMDroid_GeoPoint
 
 arrCoordinates = GetCoordinates
 General.RunLog("ShowMap, Lat: " & arrCoordinates(0) & ", Lon: " & arrCoordinates(1))

 GeoPoint1.Initialize(arrCoordinates(0), arrCoordinates(1))
 
 MapView1.Initialize("")
 MapView1.SetBuiltInZoomControls(True)
 MapView1.SetMultiTouchControls(True)

 'set the zoom before the center
 MapView1.GetController.SetZoom(14)
 MapView1.GetController.SetCenter(GeoPoint1)
 
 pnlMap.AddView(MapView1, 0,0, pnlMap.Width, pnlMap.Height)
 
 GotoPanel(ePanelType.ShowMap, False)
 
End Sub

Again, this shows the map background fine, but no map data.
I am sure I must be missing some simple, essential step somewhere, but can't see it.
Any suggestions?

RBS

Solved this now.
Needed to add:

B4X:
 rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
 Wait For Activity_PermissionResult(Permission As String, Result As Boolean)

No idea why the demo project didn't need to do this.

RBS
 
Upvote 0

MaFu

Well-Known Member
Licensed User
Longtime User
Compare the targetSDKVersion in the Manifest editor between the demo and your project. The demo may have set an older version and therefore the permission entry is not needed.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Compare the targetSDKVersion in the Manifest editor between the demo and your project. The demo may have set an older version and therefore the permission entry is not needed.

Yes, that must be it. I have 26 in my project and example project has 14.

RBS
 
Upvote 0
Top