android-how to remove lines on map -
i'm drawing lines between 2 position on map , works fine .
i need remove them when want draw new line . code :
polylineoptions lineoptions; arraylist<latlng> points = null; for(int i=0;i<result.size();i++){ points = new arraylist<latlng>(); list<hashmap<string, string>> path = result.get(i); for(int j=0;j<path.size();j++){ hashmap<string,string> point = path.get(j); if(j==0){ distance = (string)point.get("distance"); continue; }else if(j==1){ duration = (string)point.get("duration"); continue; } double lat = double.parsedouble(point.get("lat")); double lng = double.parsedouble(point.get("lng")); latlng position = new latlng(lat, lng); points.add(position); } } lineoptions.addall(points); lineoptions.width(3); lineoptions.color(color.red); map.addpolyline(lineoptions);
i tried map.clear() , didn't work . how can clear lines on map ?
thanks you
make arraylist
arraylist<polyline> polylinearraylist;
in oncreate method
polylinearraylist = new arraylist<polyline>();
update code one
// flusing markers drawn (int icount = 0; icount < polylinearraylist.size(); icount++) { polyline polyline = polylinearraylist.get(icount); polyline.remove(); } polyline mpolyline = null; polylineoptions lineoptions; arraylist<latlng> points = null; for(int i=0;i<result.size();i++){ points = new arraylist<latlng>(); list<hashmap<string, string>> path = result.get(i); for(int j=0;j<path.size();j++){ hashmap<string,string> point = path.get(j); if(j==0){ distance = (string)point.get("distance"); continue; }else if(j==1){ duration = (string)point.get("duration"); continue; } double lat = double.parsedouble(point.get("lat")); double lng = double.parsedouble(point.get("lng")); latlng position = new latlng(lat, lng); points.add(position); } } lineoptions.addall(points); lineoptions.width(3); lineoptions.color(color.red); mpolyline = googlemap.addpolyline(lineoptions);
add polyline arraylist
polylinearraylist.add(mpolyline);
Comments
Post a Comment