how to remove overlays from mapview with index in osmdroid?

25 views Asked by At

I add my overlays to osmdroid mapview with index as below:

kmzOverlay.setName(fileName);
kmzFolderOverlay.add(kmzOverlay);
mapView.getOverlays().add(kmzId,kmzOverlay);
mapView.invalidate();

now when I want remove overlays with this code:

mapView.getOverlays().remove(index);
mapView.invalidate();

the overlays didn't remove from mapview.

how can I fix this?

1

There are 1 answers

0
Yousha Aleayoub On

When removing overlays from an osmdroid MapView, ensure that you are using the correct index for the overlay you want to remove. The index should match the position of the overlay in the overlays list.

So I think this should work:

mapView.getOverlays().remove(kmzId);
mapView.invalidate();

By directly using kmzId instead of a separate index variable, you can accurately target the overlay for removal. Make sure kmzId corresponds to the correct overlay you intend to remove.