Reputation:
I've added several or more pegs to my google maps in various places and similarly added radius circles using the code below. But I'd like to remove all added circles, but keep all pegs on the map. Does anyone know how to do this?
The difference between this and most other questions on this subject is,
Code:
public static void GoogleSetup (double MapSize, double lat, double lon){
CircleOptions circleOptions = new CircleOptions()
.center(new LatLng(lat, lon)) //set center
.radius(MapSize) //set radius in meters
.fillColor(Color.argb(30, 20, 20, 140)) //default
.strokeWidth(2)
.strokeColor(Color.RED);
Circle myCircle = mGoogleMap.addCircle(circleOptions);
}
Upvotes: 2
Views: 2884
Reputation: 22232
When adding Circle
s store all of them into a List
:
Circle myCircle = mGoogleMap.addCircle(circleOptions);
myList.add(myCircle);
At some point, iterate over this list and remove all of them:
for (Circle myCircle : myList) {
myCircle.remove();
}
myList.clear();
The API provides no other way of removing visual objects except for GoogleMap.clear()
as of version 4.2.
Upvotes: 4