public final class

TileOverlay

extends Object
java.lang.Object
   ↳ com.google.android.gms.maps.model.TileOverlay

Class Overview

A Tile Overlay is a set of images which are displayed on top of the base map tiles. These tiles may be transparent, allowing you to add features to existing maps. A tile overlay has the following properties:

Tile Provider
The TileProvider provides the images that are used in the tile overlay. You must specify the tile provider before it is added to the map. The tile provider cannot be changed once it has been added; however, you can modify the behavior of the tile provider to return different images for specific coordinates. If the tiles provided by the tile provider change, you must call clearTileCache() afterwards to ensure that the previous tiles are no longer rendered.
Z-Index
The order in which this tile overlay is drawn with respect to other overlays (including GroundOverlays, Circles, Polylines, and Polygons but not Markers). An overlay with a larger z-index is drawn over overlays with smaller z-indices. The order of overlays with the same z-index is arbitrary. The default zIndex is 0.
Visibility
Indicates if the tile overlay is visible or invisible, i.e., whether it is drawn on the map. An invisible tile overlay is not drawn, but retains all of its other properties. The default is true, i.e., visible.

You must only call methods in this class on the main thread. Failure to do so will result in an IllegalStateException.

Tile Coordinates

Note that the world is projected using the Mercator projection (see Wikipedia) with the left (west) side of the map corresponding to -180 degrees of longitude and the right (east) side of the map corresponding to 180 degrees of longitude. To make the map square, the top (north) side of the map corresponds to 85.0511 degrees of latitude and the bottom (south) side of the map corresponds to -85.0511 degrees of latitude. Areas outside this latitude range are not rendered.

At each zoom level, the map is divided into tiles and only the tiles that overlap the screen are downloaded and rendered. Each tile is square and the map is divided into tiles as follows:

  • At zoom level 0, one tile represents the entire world. The coordinates of that tile are (x, y) = (0, 0).
  • At zoom level 1, the world is divided into 4 tiles arranged in a 2 x 2 grid.
  • ...
  • At zoom level N, the world is divided into 4N tiles arranged in a 2N x 2N grid.
Note that the minimum zoom level that the camera supports (which can depend on various factors) is GoogleMap.getMinZoomLevel and the maximum zoom level is GoogleMap.getMaxZoomLevel.

The coordinates of the tiles are measured from the top left (northwest) corner of the map. At zoom level N, the x values of the tile coordinates range from 0 to 2N - 1 and increase from west to east and the y values range from 0 to 2N - 1 and increase from north to south.

Example

 GoogleMap map; // ... get a map.
 TileProvider tileProvider; // ... create a tile provider.
 TileOverlay tileOverlay = map.addTileOverlay(
     new TileOverlayOptions().tileProvider(tileProvider));

Summary

Public Methods
void clearTileCache()
Clears the tile cache so that all tiles will be requested again from the TileProvider.
boolean equals(Object other)
String getId()
Gets this tile overlay's id.
float getZIndex()
Gets the zIndex of this tile overlay.
int hashCode()
boolean isVisible()
Gets the visibility of this tile overlay.
void remove()
Removes this tile overlay from the map.
void setVisible(boolean visible)
Sets the visibility of this tile overlay.
void setZIndex(float zIndex)
Sets the zIndex of this tile overlay.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public void clearTileCache ()

Clears the tile cache so that all tiles will be requested again from the TileProvider. The current tiles from this tile overlay will also be cleared from the map after calling this.

public boolean equals (Object other)

public String getId ()

Gets this tile overlay's id.

public float getZIndex ()

Gets the zIndex of this tile overlay.

Returns
  • the zIndex of the tile overlay.

public int hashCode ()

public boolean isVisible ()

Gets the visibility of this tile overlay. Note that this does not return whether the tile overlay is actually within the screen's viewport, but whether it will be drawn if it is contained in the screen's viewport.

Returns
  • this tile overlay's visibility.

public void remove ()

Removes this tile overlay from the map.

public void setVisible (boolean visible)

Sets the visibility of this tile overlay. When not visible, a tile overlay is not drawn, but it keeps all its other properties.

Parameters
visible if true, then the tile overlay is visible; if false, it is not.

public void setZIndex (float zIndex)

Sets the zIndex of this tile overlay. See the documentation at the top of this class for more information.

Parameters
zIndex the zIndex of this tile overlay.