### Replace a Marker

To replace an existing Marker, remove the Marker first to then add the Marker back again.
It is useful to use a Map (Key: Marker, Value: Title) which keeps track of the Markers placed.
'Define the GoogleMap
Private gmap As GoogleMap
'Define the markermap object and a marker which holds the last marker selected
Private MarkerMap As Map
Private SelectedMarker as Marker
'Init the markermap
MarkerMap.Initialize
'Add a new marker to the googlemap and the markermap
Dim Lat as Double = 53
Dim Lon as Double = 9
Dim MarkerTitle as String = "Marker at Homeplace"
Dim m As Marker = gmap.AddMarker(Lat, Lon, MarkerTitle)
'Add the marker as key to the markermap with the title as value
MarkerMap.Put(m, MarkerTitle)
'Keep track of the last marker selected, get the title and show f.e. in a statusbar
`Sub gmap_MarkerClick (mSelectedMarker As Marker)
SelectedMarker = mSelectedMarker
Dim title As String = MarkerMap.Get(SelectedMarker)
statusbarMain.Text = "Marker selected: " & title
End Sub`
'Replace a Marker
`Sub btnReplaceMarker_Action
'Check if a marker has been selected
If SelectedMarker.IsInitialized = False Then
fx.Msgbox2(Null, "No marker selected. Select a marker first and try again.", "Replace Marker", "OK", "", "", fx.MSGBOX_ERROR)
Return
End If
'Get the title
Dim title As String = MarkerMap.Get(SelectedMarker)
'Remove the selected Marker. IMPORTANT
'B4J v5.50 or higher
gmap.RemoveMarker(SelectedMarker)
'B4J v5.00 or earlier
'Remove the selected Marker
SelectedMarker.Remove
'Define the Marker Location
Dim mLatLng As LatLng
Dim Lat as Double = 50
Dim Lon as Double = 10
mLatLng.Initialize(Lat,Lng)
'Create the Marker at the new position
SelectedMarker = gmap.AddMarker2(Lat, Lng, title, File.GetUri(File.DirAssets, "green-dot.png"))
MarkerMap.Put(SelectedMarker, title)
statusbarMain.Text = "Marker replaced: " & MarkerMap.Get(SelectedMarker)
End Sub`

Changed: , Category: Google Maps, File: T6C197M1452.htm, ID: 1452