Clear markers from Google Map in Android

后端 未结 2 656
鱼传尺愫
鱼传尺愫 2020-12-14 05:20

I have added map on fragment activity and added several marker using addMarker function, but i am able to remove all markers , I am getting notification for different list o

2条回答
  •  抹茶落季
    2020-12-14 05:52

    If you do not wish to clear polylines and only the markers need to be removed follow the steps below.

    First create a new Marker Array like below

    List AllMarkers = new ArrayList();
    

    Then when you add the marker on the google maps also add them to the Marker Array (its AllMarkers in this example)

    for(int i=0;i

    then finally call the below method to remove all markers at once

     private void removeAllMarkers() {
            for (Marker mLocationMarker: AllMarkers) {
                mLocationMarker.remove();
            }
            AllMarkers.clear();
    
        }
    

    call from anywhere to remove all markers

    removeAllMarkers();
    

    I found this solution when i was looking for a way to remove only the map markers without clearing the polylines. Hope this will help you too.

提交回复
热议问题