Regis_AG Regis_AG -4 years ago 178
Android Question

Android Google Maps: how to remove an overlay from the map?

I have overlays on my map which are roughly created like this:

for(String date : dates)
MapCustomTileProvider tileProvider = getMapCustomTileProviderForDate(date); // MapCustomeTileProvider extends UrlTileProvider

Later in my code, I want to make some of these overlays transparent/invisible:

for (MapTileProvider tileProvider : tileProviders) {


But the map does not redraw.

How to force the refresh of the map ?

By the way, is it possible to adjust the transparency (alpha) of an overlay ?

Thanks !!!

Answer Source

The addTileOverlay method returns a TileOverlay object that you can work with:

TileOverlay overlay = mMap.addTileOverlay(tileProvider.overlayOptions);
overlay.setVisible(false); // Make the overlay invisible
overlay.remove(); // Remove the tile overlay from the map.

You may want to change your tileProviders to be List<TileOverlay> to work with your overlays:

List<TileOverlay> tileOverlays = new ArrayList<TileOverlay>

// ...

for (TileOverlay tileOverlay : tileOverlays) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download