Android Question Google maps markers' animation

tigrot

Well-Known Member
Licensed User
Longtime User
Hi everybody,
I have seen examples of markers' animation. I'm looking for a way to monitor a group of locations on a map showing the new position( and eventually move the marker) while it becomes available.
I was not able to find an example on B4X. Anybody knows how to do?

Best regards and thanks !

Mauro Zanin
 

JordiCP

Expert
Licensed User
Longtime User
If you want to "update" the markers position as you keep receiving new coordinates for those points, you should keep a reference to the markers in a map when you create them

Then add a code similar to this example. It is not complete as you need to init PersonList and MarkersMap first with the appropiate values
B4X:
Sub Process_Globals
   Type PersonType ( _
        Id As Int, _
        Position As LatLng, _
        LastReceived As Long)  
   Dim PersonList as List
   Dim MarkersMap as Map
End Sub

' To be called when you have updated positions for the persons in PersonList
' MarkersMap has to be initialized before, when you first create the markers, using the person as a key and the marker itself as the value
Sub UpdateExistingMarkers
    for each person as personType in PersonList
       Dim m As Marker = MarkersMap.Get(person)
       Dim NewPosition As LatLng
       NewPosition.Initialize(person.Position.Latitude,person.Position.Longitude)
       m.Position=NewPosition
    Next
End Sub
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Yes, you are right!

To update only some persons, I would add a "flag" to the personType struct, to handle which ones need to be updated, and change the code this way

B4X:
Sub Process_Globals
   Type PersonType ( _
      Id As Int, _
      Position AsLatLng, _
      flgHaveNewCoords as Boolean, _
      LastReceived As Long)
   Dim PersonList as List
   Dim MarkersMap asMap
End Sub

' To be called when you have updated positions for the persons in PersonList
' MarkersMap has to be initialized before, when you first create the markers, using the person as a key and the marker itself as the value
Sub UpdateExistingMarkers
   For each person as personType in PersonList
      if person.flgHaveNewCoords=True then
         Dim m AsMarker = MarkersMap.Get(person)
         Dim NewPosition AsLatLng
         NewPosition.Initialize(person.Position.Latitude,person.Position.Longitude)
         m.Position=NewPosition
         person.flgHaveNewCoords=False
      End If
   Next
End Sub
 
Upvote 0
Top