Android Question Markers are not showing in OSMdroid????

Mark Read

Well-Known Member
Licensed User
I am using OSMDroid to create a navi for waterways. It is basically working but....

The main activity calls the navi activity via the TouchEventsOverlay1_LongCLick event. The navi activity calculates a path and creates a series of markers stored in list "Markers", which is globally dimensioned in the main activity. After finishing the navi activity, the main resume event is called and using the rapid debugger, I can see that there are eg. 15 markers in the list but they do not show on the map.
Can anyone see what is going on in the code before I have to post the whole source code?

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim TileSource As String="Mapnik"                                        'Mapnik, OSMPublicTransport, MapquestOSM
    Dim dt As String="Maptemp"                                                            'Filename for screenshot
    Dim FirstPointLon, FirstPointLat, SecondPointLon, SecondPointLat As Double            'Gps coordinates of start and finish markers
    Dim FirstPointClicked As Boolean=False
    Dim Timer1 As Timer                                                                    'Used to create a delay
    Dim NordValues(4) As Double                                                            'Returns lat & lon of bounding box for markers
    Dim ActWidth, ActHeight As Int                                                        'activity height & width
    Dim Markers As List
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim MapView1 As MapView
    Dim MapCenter As GeoPoint
    Dim TouchEventsOverlay1 As TouchEventsOverlay                                        'Allows click & long click events
    Dim SimpleLocationOverlay1 As SimpleLocationOverlay
'    Dim BoundaryBox As BoundingBox
    Dim FirstMarker, SecondMarker As Marker
    Dim MarkersOverlay1 As MarkersOverlay   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Markers.Initialize   'initialise list for markers
   Timer1.Initialize( "Timer1",500)
   '  pass an EventName when initializing the MapView
     '  MapView has two events: CenterChanged and ZoomChanged
   Activity.AddView(MapView1, 0, 0, 100%x, 100%y)
   MapCenter.Initialize(47.3763900,15.0911300)   'Leoben as center

   Activity.Title="OSMDroid ["&MapView1.Zoom&"]"
   'Log("MapView1.Center: " & MapView1.GetCenter)
   'initialize the SimpleLocationOverlay and add it to the MapView
     'set the SimpleLocationOverlay to display it's icon at the map center
   'initialize the MarkersOverlay and add it to the MapView
     'an EventName is required as we will listen for the two events that MarkersOverlay generates
  MarkersOverlay1.Initialize(MapView1, "") 'No events
   'Add touch events to map
   'Log("Before Timer1: " & MapView1.GetBoundingBox2(MapView1.Width, MapView1.Height))
   Timer1.Enabled=True   'Wait for a short period for map to finish drawing
End Sub

Sub Activity_Resume
   'We return here when pathfinder activity is closed
   'initialize the MarkersOverlay and add it to the MapView
     'an EventName is required as we will listen for the two events that MarkersOverlay generates
  MarkersOverlay1.Initialize(MapView1, "") 'No events
   'add the List of Markers to the MarkersOverlay
   Log("Markers: " & Markers.Size)
End Sub


Well-Known Member
Licensed User
Hey Mark,
did you checked the coordinates of your points, if they are in the visible part of your map? And what icon did you use? The best is, to use a icon like this:

   Dim m As Marker
   Dim Icon As BitmapDrawable
   Icon = AndroidResources1.GetApplicationDrawable("marker_default")
   m.Initialize("Test", "Test it" , 47.3763900, 15.0911300, Icon)

where the icon lies in the drawable-nodpi folder. I have attached your code with an example of one marker which is displayed correctly.

All the best


    10.5 KB · Views: 232
Upvote 0

Mark Read

Well-Known Member
Licensed User
Thanks for your reply Stefan. I checked the coordinates, they were indeed rubbish. The points are calculated from pixel coordinates and there were various problems. The marker had always the geopoint value 0,-720 which cannot be displayed. Now all is correct and working.
Upvote 0