简体   繁体   中英

How do I remove all radius circles from Google map android but keep pegs?

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 ,

  1. I want to remove all circles simultaneously
  2. Whilst keeping all pegs on the map

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);

}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM