OSM Droid Markers problem

stephankuba

Member
Licensed User
Longtime User
Hello,

i want to add a marker if button is down, but i don't have any idea?
I use this code.

B4X:
Sub Process_Globals
   Dim MapCenter As GeoPoint
   Dim TileSource As String
   Dim ZoomLevel As Int
End Sub

Sub Globals
   Dim MapView1 As MapView
   Dim MinimapOverlay1 As MinimapOverlay
   Dim ScaleBarOverlay1 As ScaleBarOverlay
   Dim TileSourceSpinner As Spinner
   
   '   create the MarkersOverlay
   Dim MarkersFocusOverlay1 As MarkersFocusOverlay
End Sub

Sub Activity_Create(FirstTime As Boolean)
   '   update the MenuItems
   Activity.AddMenuItem("Fit map to markers", "MenuItemSelect")
   
   '   MapView initialized with no EventName as we'll not be listening for MapView events
   MapView1.Initialize("")
   Activity.AddView(MapView1, 0, 48dip, 100%x, 100%y-48dip)
   
   MapView1.SetMultiTouchEnabled(True)
   MapView1.SetZoomEnabled(True)
   
   '   initialize the MarkersFocusOverlay and add it to the MapView
   MarkersFocusOverlay1.Initialize(MapView1)
   
   MarkersFocusOverlay1.SetInfoWindowBackgroundColor(Colors.Gray)
   MarkersFocusOverlay1.SetInfoWindowDescriptionColor(Colors.Cyan)
   MarkersFocusOverlay1.SetInfoWindowDescriptionSize(24)
   MarkersFocusOverlay1.SetInfoWindowMaxWidth(80%x)
   MarkersFocusOverlay1.SetInfoWindowTitleColor(Colors.Red)
   MarkersFocusOverlay1.SetInfoWindowTitleSize(30)
   
   MapView1.AddOverlay(MarkersFocusOverlay1)
   
   '   create and initialize 2 Markers
   
   '   for Marker1 i'll use a custom icon
   Dim Icon As BitmapDrawable
   Icon.Initialize(LoadBitmap(File.DirAssets, "my_icon.png"))
   
   Dim Marker1 As Marker
   Marker1.Initialize("Home sweet home", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi egestas suscipit convallis. Etiam pellentesque gravida est, quis luctus nunc commodo at. Nam et risus orci. Integer malesuada lorem dolor. Maecenas vestibulum cursus enim, tincidunt luctus libero placerat non. In vitae metus tellus, nec euismod nibh. Phasellus ut quam vitae justo sagittis auctor. Sed vel sapien dolor. Etiam ut sem id dolor iaculis ullamcorper. Aenean eget sem nibh, a tempor augue. Nulla interdum luctus molestie.", 52.75610, 0.39748, Icon)
   
   '   Marker2 will display the default OSMDroid icon
   '   the default icon is used if Null is passed as the Icon parameter
   Dim Marker2 As Marker
   Marker2.Initialize("Elsewhere", "Downham Market", 52.60801, 0.39047, Null)
   
   '   create a List and initialize it with the 2 Markers
   Dim Markers As List
   
   '   ** example code updated **
   '   Markers.Initialize2(Array As Marker(Marker1, Marker2))   '   this is the previous code
   Markers.Initialize2(Array As Object(Marker1, Marker2))      '   this is the new code

   '   add the List of Markers to the MarkersFocusOverlay
   MarkersFocusOverlay1.AddMarkers(Markers)
   
   If FirstTime Then
      TileSource="Mapnik"
      
      '   fit the MapView to the MarkersFocusOverlay
      MapView1.FitMapToBoundingBox(MarkersFocusOverlay1.GetBoundingBox)
   Else
      '   restore saved zoom level and map center
      MapView1.Zoom=ZoomLevel
      MapView1.SetCenter3(MapCenter)
   End If
   
   
   ScaleBarOverlay1.Initialize(MapView1)
   MapView1.AddOverlay(ScaleBarOverlay1)
   
   '   ensure that the MinimapOverlay is the LAST overlay added to the MapView
   MinimapOverlay1.Initialize(MapView1)
   MapView1.AddOverlay(MinimapOverlay1)
   
   TileSourceSpinner.Initialize("TileSourceSelect")
   Activity.AddView(TileSourceSpinner, 0, 0, 100%x, 48dip)
   
   TileSourceSpinner.AddAll(MapView1.GetTileSources)
   TileSourceSpinner.Prompt="Select a TileSource"
   TileSourceSpinner.SelectedIndex=TileSourceSpinner.IndexOf(TileSource)
   TileSourceSelect_ItemClick(TileSourceSpinner.SelectedIndex, TileSourceSpinner.SelectedItem)
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   MapCenter=MapView1.GetCenter
   TileSource=MapView1.GetTileSource
   ZoomLevel=MapView1.Zoom
End Sub

Sub MenuItemSelect_Click
   Dim MenuItem As String
   MenuItem=Sender
   Select MenuItem
      Case "Fit map to markers"
         '   fit the MapView to the MarkersFocusOverlay
         MapView1.FitMapToBoundingBox(MarkersFocusOverlay1.GetBoundingBox)
   End Select
End Sub

Sub TileSourceSelect_ItemClick (Position As Int, Value As Object)
   MapView1.SetTileSource(Value)
   MinimapOverlay1.SetTileSource(Value)
End Sub

My problem is how to add marker here automatic if i add a new marker.
B4X:
Markers.Initialize2(Array As Object(Marker1, Marker2))

I want to put this in a loop an make new markers on map.
B4X:
   Dim Marker2 As Marker
   Marker2.Initialize("Elsewhere", "Downham Market", 52.60801, 0.39047, Null)

this dont work

B4X:
Dim Marker & i As Marker
   Marker & i.Initialize("Elsewhere", "Downham Market", 52.60801, 0.39047, Null)
i know this is a silly try, but i realy dont know how to make it work.

maybe someone can help me, thank you.
 
Top