Android Question Multiple polylines in GoogleMap

Discussion in 'Android Questions' started by marcick, May 8, 2015.

  1. marcick

    marcick Well-Known Member Licensed User

    Hi all,
    I dinamically add/remove several markers on the map.
    Each marker then can moves and follow a path.
    I would like that each marker draw a line while it moves but each line must be of course indipendent.
    I've already played with polylines but just for one marker

    Code:
    Dim l1 As LatLng
        l1.Initialize(lat,lon)
        Points.Add(l1)
        
    If Pline.IsInitialized=False Then Pline=GoogleMap1.AddPolyline
        Pline.Points=Points
        Pline.Color=
    Colors.blue
    So everytime the Lat/Lon changes, a new point is added and the line is drawn.

    What now for creating an array of polylines and manage each one indipentently ?
    Hope the question is clear.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    How can you determine which marker belong to which polygon? Based on the distance?
     
  3. marcick

    marcick Well-Known Member Licensed User

    Hi Erel,
    I have a map that keep track of each marker I add on the googlemap, with all parameters, lat, Lon, title etc.
    when marker "John" changes it position, a new segment from its old to new position need to be drawn on the map.
    so I think for each new marker that appear I need to declare a new polyline and new points object.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    I see. How are you monitoring the dragging event? With GoogleMapsExtra library?

    You should use a Map that maps between the markers and the polygons. This will allow you to get the polygon and add a new point each time.
     
  5. marcick

    marcick Well-Known Member Licensed User

    Yes, I'm using GoogleMapsExtra library.

    I'm sure the solution is very simple but I'm a bit disoriented.
    Actually i have declared in globals:

    Code:
    Dim Pline As Polyline
    Dim Points As List
    Now, when the marker changes its position, I use this code to add a segment to the polyline

    Code:
    Sub Add_Track(la As String, lo As String)

        
    Dim l1 As LatLng
        l1.Initialize(la,lo)
        Points.Add(l1)
        
    If Pline.IsInitialized=False Then Pline=GoogleMap1.AddPolyline
        Pline.Points=Points
        Pline.Color=
    Colors.blue
        Pline.ZIndex=
    3
       
    End Sub
    My problem is that each marker needs a separate polyline, otherwise if marker "John" moves, then marker "Paul" moves, I have a segment that connect John to Paul and that's not correct. The Pline of John must be separated form Paul's one.
    So, when Marker "John" is first time created on the map, I need to create a John_Pline.
    I suppose I have to create an array of polylines but I'm a bit confused .....
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You need to use a Map (hashtable).

    The keys of the map will be the markers and the values will be the polylines.
    Something like
    Code:
    Sub AddPointToMarker(marker1 As Marker, lat As Double. Lon As Double)
     
    If HashMap.ContainsKey(marker1) = False Then
      
    Dim pline As Polyline = GoogleMap1.AddPolyline
      HashMap.Put(marker1, pline)
    End If
    Dim pline As Polyline = HashMap.Get(marker1)
    dim ll As LatLng
    ll.Initialize(...)
    Dim points As List = pline.Points
    points.Add(ll)
    pline.Points = points
    End Sub
     
  7. marcick

    marcick Well-Known Member Licensed User

    Super !
    Many thanks again
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice