I'm trying to remove my previously created polyline before creating one, this is what I have:
protected void fazerCaminho(ArrayList<HashMap<String, String>> listaPolylines) {
if (line == null) {
for (Map polyline : listaPolylines) {
List<LatLng> decodedPath = PolyUtil.decode((String) polyline.get("points"));
line = mMap.addPolyline(new PolylineOptions()
.width(3)
.color(Color.rgb(25, 151, 152))
.geodesic(true)
.addAll(decodedPath));
}
} else {
line.remove();
for (Map polyline : listaPolylines) {
List<LatLng> decodedPath = PolyUtil.decode((String) polyline.get("points"));
line = mMap.addPolyline(new PolylineOptions()
.width(3)
.color(Color.rgb(25, 151, 152))
.geodesic(true)
.addAll(decodedPath));
}
}
}
The line.remove doesn't work, this solution worked on a previous version but back then I didn't have the for method, what am I doing wrong?