B4J Question jgooglemaps remove label

bvonlaar

Member
Licensed User
Longtime User
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)

When I use:
B4X:
SetMarkerLabel(gmap.AddMarker2(llat, llong, "",File.GetUri(File.DirAssets,RMarkTyp)),MLabel,RLColor,"18px")

the specified label is set, but how can I remove it later? And how can I manage to remove a lot of labels with one call.

regards,
Benedikt
 

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

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.
 

Attachments

  • GoogleMapsEx.zip
    9.2 KB · Views: 264
Last edited:
Upvote 0

bvonlaar

Member
Licensed User
Longtime User
Hi,

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:

Dim PLine As Polyline

For library version 1.61 it is:

Dim PLine As MapPolyline

Thanks again!

Benedikt
 
Upvote 0
Top