How to clear all map overlays or markers from google map in android?

I want to remove all map overlays or markers from a Google map and using the following code

if(!mapOverlays.isEmpty())
     {
     mapOverlays.clear();

 }

which gives me an exception, can anyone direct me? Am I right or wrong, if I am wrong, kindly provided me with a solution to my problem.

I want the map to be blank if it has a marker on it.

any help would be assigned.

+3
source share
2 answers
mapView.invalidate();

I was unable to update the map. now works fine. so all code looks like

if(!mapOverlays.isEmpty()) 
     { 
     mapOverlays.clear(); 
     mapView.invalidate();

 }
+17
source

If you need to completely clear map overlays, you need to clear the ListArray in a class that extends ItemizedOverlay.

Something like that:

    mItemizedOverlay.clearOverlays();
    mMapView.getOverlays().clear();
    mMapView.invalidate();
+1

Source: https://habr.com/ru/post/1739309/


All Articles