update polyline according to the user moving android googleMaps v2

dvrm picture dvrm · Jun 11, 2013 · Viewed 14.7k times · Source

I have googleMap (v2) with polyline that presents a route between the user current location and the destination point.
Now, I want to update the polyline according to the user moving.

I tried to redrawing the whole polyline when location is changed but the polyline is flickering.

I didn't find any appropriate function in the PolylineOptions class
(the function add() is only to add a vertex but not to update or remove)

do you have any idea how to update the polyline ???
thank you for giving your time.

Answer

MaciejGórski picture MaciejGórski · Jun 11, 2013

The only way as of version 3.1.36:

List<LatLng> points = polyline.getPoints();
points.add(newPoint);
polyline.setPoints(points);

Hopefully the API will be enhanced in later versions.