Android Question Change color of (polyline pline)

yfleury

Active Member
Licensed User
Longtime User
Hello
Using googlemapsExtra, I created a route with markers. I drew the road with the polypoints and pline.

I want to know how to change the color of the road as the vehicle moves along the road.
Screenshot_20210828-153829.jpg
 

TILogistic

Expert
Licensed User
Longtime User
example:
if the routes are in a variable of type map.

B4X:
    Dim PolylineRoute As Polyline = Route.route_polyline
    PolylineRoute.Visible = True
    PolylineRoute.Color = Colors.Yellow
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
you must perform some calculations with the current position of the car, with the previous and next position of the route.

Attach a project to help you.
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
I have a list of polypoints in DB and use it with these sub

B4X:
Sub Affiche_les_routes
    LogColor ("Affiche_les_routes ", Colors.Magenta)
    Load_Polypoints 'from DB
    For x=0 To polyPoints.Size-1
        drawDirections(x)
    Next
End Sub

Sub drawDirections (numeroRoute As Int)
'    LogColor("drawDirections ",Colors.Blue)
    Dim jo As JavaObject
    Dim Points As List
    Points.Initialize
    jo.InitializeContext

    Points = jo.RunMethod("decodePoly", Array(polyPoints.Get(numeroRoute)))
    If Points.Size > 0 And Gmap.IsInitialized Then
        pline = Gmap.AddPolyline
        pline.Points = Points
'        pline.Color = Colors.red
    End If
End Sub

I can draw all polypoints
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Exactly I want change color from black (front of car) to green (back of car)

If you don't want to do calculations, this can help.


1.- You must check if the point (location of the car) is within a segment of the polyline.

2.- You need to know the direction or steering angle of the car and the angle of the segment it is on.

3.- Draw the polyline from the beginning of the segment to the point of the car and from this to the end of the segment.

reference:
etc.
 
Last edited:
Upvote 0
Top