Abdullah
Abdullah

Reputation: 37

How to remove all circles on map

I have added radius circles using the code below. But I'd like to remove all added circles. Also I want to limit drawing circles 3 or 4 circles .

@Override
        public void onMapClick(LatLng point) {
        CircleOptions circleOptions = new CircleOptions()
        .center(point)   //set center
        .radius(500)   //set radius in meters
        .fillColor(Color.TRANSPARENT)  //default
        .strokeColor(Color.BLUE)
        .strokeWidth(5);

        for(int i=0 ; 0 < 3 ; i++){
         myCircle = myMap.addCircle(circleOptions);
}
}

Upvotes: 0

Views: 1439

Answers (1)

Drublic
Drublic

Reputation: 709

I think this should do the trick. Create an arraylist that keeps track of all the Circles you add to the map, and call DeleteCircles() when you want to delete the Circles from the map.

public class CustomMapFragment{

static List<Circle> mCircleList;

@Override
public void onMapClick(LatLng point) {

    if (mCircleList==null){
            mCircleList = new ArrayList<Circle>();
    }

    CircleOptions circleOptions = new CircleOptions()
    .center(point)   //set center
    .radius(500)   //set radius in meters
    .fillColor(Color.TRANSPARENT)  //default
    .strokeColor(Color.BLUE)
    .strokeWidth(5);

    if (mCircleList.size()<3){
    Circle mCircle = myMap.addCircle(circleOptions);
    mCircleList.add(mCircle)
    }
}

public void deleteCircles(){

    for (int i = 0 ; i <= mCircleList.size() -1; i++){
    Circle mCircle = mCircleList.get(i);
    mCircle.remove();
    }
    mCircleList.clear();
}
}

Upvotes: 1

Related Questions