android - How to remove all the polylines from a map -
android - How to remove all the polylines from a map -
following
how draw path between 2 markers
i had add together lot of polylines between 2 markers, create path.
one of markers draggable, lets source draggable.
so, when user starts dragging marker, path drawn must erased , new path between new source , destination must draw.
i able draw new path, how can erase previous path?
this how path drawn:
(int z = 0; z < list.size() - 1; z++) { latlng src = list.get(z); latlng dest = list.get(z + 1); polyline line = map.addpolyline(new polylineoptions() .add(new latlng(src.latitude, src.longitude), new latlng(dest.latitude, dest.longitude)) .width(2).color(color.red).geodesic(true)); }
one solution can is
map.clear();
to clear polylines, markers etc.. , add together markers again, drawn path.
but start dragging, marker cleared, hence not visible on map :(
thank you
keep track of polyline add together map:
polyline polyline = this.mmap.addpolyline(new polylineoptions().....);
then when want remove it:
polyline.remove();
if have lots of polylines, add together them list set on map:
list<polyline> polylines = new arraylist<polyline>(); for(....) { polylines.add(this.mmap.addpolyline(new polylineoptions()....)); }
and when want delete:
for(polyline line : polylines) { line.remove(); } polylines.clear();
the key maintain reference polyline objects , phone call .remove() on each one.
android google-maps google-maps-android-api-2
Comments
Post a Comment