Hello,
I load GPS-Positions from a csv-file and place different marker. The setting and removing of marker works fine. For some reasons I want also to set labels, but also remove them later.
For setting the labels I use:
B4X:
Sub SetMarkerLabel(mm As Marker, text As String, color As String,fontSize As String)
Dim jo As JavaObject= mm
jo=jo.RunMethod("getJSObject",Null)
Log(jo.RunMethod("eval", Array($"this.setLabel({text: "${text}",color: "${color}","fontSize": "18px"});"$)))
End Sub
The actual call for placing the marker is:
B4X:
Dim M As Marker =gmap.AddMarker2(llat, llong, "",File.GetUri(File.DirAssets,RMarkTyp))
MMap(RNoC-1).Put(i,M)
pls find attached example which uses various Google Maps API methods including RemoveLabel :
B4X:
Sub RemoveMarkerLabel(m As Marker)
Dim jo As JavaObject = m
jo = jo.RunMethod("getJSObject", Null)
Dim propertyjs As String = $"this.setLabel(null);"$
jo.RunMethod("eval", Array(propertyjs))
End Sub
To remove all Marker Labels, use like - not included in the attached example
B4X:
Sub RemoveAllMarkerLabels
Log("Remove All Marker Labels")
If MarkerList.Size = 0 Then Return
For Each m As Marker In MarkerList
RemoveMarkerLabel(m)
Next
End Sub
The MarkerList keeps track of the markers defined - see attached example.
pls find attached example which uses various Google Maps API methods including RemoveLabel :
B4X:
Sub RemoveMarkerLabel(m As Marker)
Dim jo As JavaObject = m
jo = jo.RunMethod("getJSObject", Null)
Dim propertyjs As String = $"this.setLabel(null);"$
jo.RunMethod("eval", Array(propertyjs))
End Sub
To remove all Marker Labels, use like - not included in the attached example
B4X:
Sub RemoveAllMarkerLabels
Log("Remove All Marker Labels")
If MarkerList.Size = 0 Then Return
For Each m As Marker In MarkerList
RemoveMarkerLabel(m)
Next
End Sub
The MarkerList keeps track of the markers defined - see attached example.
It has taken a while until I was able to implement your solution. I had to arrange my marker objects new.
The example was also a great help. I guess it was written for another library version.
In the declaration you use: