public final class

GoogleMap

extends Object
java.lang.Object
   ↳ com.google.android.gms.maps.GoogleMap

Class Overview

This is the main class of the Google Maps Android API and is the entry point for all methods related to the map. You cannot instantiate a GoogleMap object directly, rather, you must obtain one from the getMap() method on a MapFragment or MapView that you have added to your application.

Note: Similar to a View object, a GoogleMap can only be read and modified from the main thread. Calling GoogleMap methods from another thread will result in an exception.

Developer Guide

To get started, read the Google Maps Android API v2 developer guide.

Summary

Nested Classes
interface GoogleMap.CancelableCallback A callback interface for reporting when a task is complete or cancelled. 
interface GoogleMap.InfoWindowAdapter Provides views for customized rendering of info-windows. 
interface GoogleMap.OnCameraChangeListener Defines signatures for methods that are called when the camera changes position. 
interface GoogleMap.OnInfoWindowClickListener Callback interface for click/tap events on a marker's info window. 
interface GoogleMap.OnMapClickListener Callback interface for when the user taps on the map. 
interface GoogleMap.OnMapLongClickListener Callback interface for when the user long presses on the map. 
interface GoogleMap.OnMarkerClickListener Defines signatures for methods that are called when a marker is clicked or tapped. 
interface GoogleMap.OnMarkerDragListener Callback interface for drag events on markers. 
interface GoogleMap.OnMyLocationChangeListener Callback interface for when the My Location dot/chevron (which signifies the user's location) changes location. 
Constants
int MAP_TYPE_HYBRID Satellite maps with a transparent layer of major streets.
int MAP_TYPE_NONE No base map tiles.
int MAP_TYPE_NORMAL Basic maps.
int MAP_TYPE_SATELLITE Satellite maps with no labels.
int MAP_TYPE_TERRAIN Terrain maps.
Public Methods
final Circle addCircle(CircleOptions options)
Add a circle to this map.
final GroundOverlay addGroundOverlay(GroundOverlayOptions options)
Adds an image to this map.
final Marker addMarker(MarkerOptions options)
Adds a marker to this map.
final Polygon addPolygon(PolygonOptions options)
Adds a polygon to this map.
final Polyline addPolyline(PolylineOptions options)
Adds a polyline to this map.
final TileOverlay addTileOverlay(TileOverlayOptions options)
Adds a tile overlay to this map.
final void animateCamera(CameraUpdate update, int durationMs, GoogleMap.CancelableCallback callback)
Moves the map according to the update with an animation over a specified duration, and calls an optional callback on completion.
final void animateCamera(CameraUpdate update, GoogleMap.CancelableCallback callback)
Animates the movement of the camera from the current position to the position defined in the update and calls an optional callback on completion.
final void animateCamera(CameraUpdate update)
Animates the movement of the camera from the current position to the position defined in the update.
final void clear()
Removes all markers, overlays, and polylines from the map.
final CameraPosition getCameraPosition()
Gets the current position of the camera.
final int getMapType()
Gets the type of map that's currently displayed.
final float getMaxZoomLevel()
Returns the maximum zoom level for the current camera position.
final float getMinZoomLevel()
Returns the minimum zoom level.
final Location getMyLocation()
Returns the currently displayed user location, or null if there is no location data available.
final Projection getProjection()
Returns a Projection object that you can use to convert between screen coordinates and latitude/longitude coordinates.
final UiSettings getUiSettings()
Gets the user interface settings for the map.
final boolean isIndoorEnabled()
Gets whether indoor maps are currently enabled.
final boolean isMyLocationEnabled()
Gets the status of the my-location layer.
final boolean isTrafficEnabled()
Checks whether the map is drawing traffic data.
final void moveCamera(CameraUpdate update)
Repositions the camera according to the instructions defined in the update.
final boolean setIndoorEnabled(boolean enabled)
Sets whether indoor maps should be enabled.
final void setInfoWindowAdapter(GoogleMap.InfoWindowAdapter adapter)
Sets a custom renderer for the contents of info windows.
final void setLocationSource(LocationSource source)
Replaces the location source of the my-location layer.
final void setMapType(int type)
Sets the type of map tiles that should be displayed.
final void setMyLocationEnabled(boolean enabled)
Enables or disables the my-location layer.
final void setOnCameraChangeListener(GoogleMap.OnCameraChangeListener listener)
Sets a callback that's invoked when the camera changes.
final void setOnInfoWindowClickListener(GoogleMap.OnInfoWindowClickListener listener)
Sets a callback that's invoked when a marker info window is clicked.
final void setOnMapClickListener(GoogleMap.OnMapClickListener listener)
Sets a callback that's invoked when the map is tapped.
final void setOnMapLongClickListener(GoogleMap.OnMapLongClickListener listener)
Sets a callback that's invoked when the map is long pressed.
final void setOnMarkerClickListener(GoogleMap.OnMarkerClickListener listener)
Sets a callback that's invoked when a marker is clicked.
final void setOnMarkerDragListener(GoogleMap.OnMarkerDragListener listener)
Sets a callback that's invoked when a marker is dragged.
final void setOnMyLocationChangeListener(GoogleMap.OnMyLocationChangeListener listener)
Sets a callback that's invoked when the my location dot changes location.
final void setTrafficEnabled(boolean enabled)
Toggles the traffic layer on or off.
final void stopAnimation()
Stops the camera animation if there is one in progress.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int MAP_TYPE_HYBRID

Satellite maps with a transparent layer of major streets.

Constant Value: 4 (0x00000004)

public static final int MAP_TYPE_NONE

No base map tiles.

Constant Value: 0 (0x00000000)

public static final int MAP_TYPE_NORMAL

Basic maps.

Constant Value: 1 (0x00000001)

public static final int MAP_TYPE_SATELLITE

Satellite maps with no labels.

Constant Value: 2 (0x00000002)

public static final int MAP_TYPE_TERRAIN

Terrain maps.

Constant Value: 3 (0x00000003)

Public Methods

public final Circle addCircle (CircleOptions options)

Add a circle to this map.

Parameters
options A circle options object that defines how to render the Circle
Returns
  • The Circle object that is added to the map

public final GroundOverlay addGroundOverlay (GroundOverlayOptions options)

Adds an image to this map.

Parameters
options A ground-overlay options object that defines how to render the overlay. Options must have an image (AnchoredBitmap) and position specified.
Returns
Throws
IllegalArgumentException if either the image or the position is unspecified in the options.

public final Marker addMarker (MarkerOptions options)

Adds a marker to this map.

The marker's icon is rendered on the map at the location Marker.position. Clicking the marker centers the camera on the marker. If Marker.title is defined, the map shows an info box with the marker's title and snippet. If the marker is draggable, long-clicking and then dragging the marker moves it.

Parameters
options A marker options object that defines how to render the marker.
Returns
  • The Marker that was added to the map.

public final Polygon addPolygon (PolygonOptions options)

Adds a polygon to this map.

Parameters
options A polygon options object that defines how to render the Polygon.
Returns
  • The Polygon object that is added to the map.

public final Polyline addPolyline (PolylineOptions options)

Adds a polyline to this map.

Parameters
options A polyline options object that defines how to render the Polyline.
Returns
  • The Polyline object that was added to the map.

public final TileOverlay addTileOverlay (TileOverlayOptions options)

Adds a tile overlay to this map. See TileOverlay for more information.

Note that unlike other overlays, if the map is recreated, tile overlays are not automatically restored and must be re-added manually.

Parameters
options A tile-overlay options object that defines how to render the overlay. Options must have a TileProvider specified, otherwise an IllegalArgumentException will be thrown.
Returns
Throws
IllegalArgumentException if the TileProvider is unspecified in the options.

public final void animateCamera (CameraUpdate update, int durationMs, GoogleMap.CancelableCallback callback)

Moves the map according to the update with an animation over a specified duration, and calls an optional callback on completion. See CameraUpdateFactory for a set of updates.

If getCameraPosition() is called during the animation, it will return the current location of the camera in flight.

Parameters
durationMs The duration of the animation in milliseconds. This must be strictly positive, otherwise an IllegalArgumentException will be thrown.
callback An optional callback to be notified from the main thread when the animation stops. If the animation stops due to its natural completion, the callback will be notified with onFinish(). If the animation stops due to interruption by a later camera movement or a user gesture, onCancel() will be called. The callback should not attempt to move or animate the camera in its cancellation method.

public final void animateCamera (CameraUpdate update, GoogleMap.CancelableCallback callback)

Animates the movement of the camera from the current position to the position defined in the update and calls an optional callback on completion. See CameraUpdateFactory for a set of updates.

During the animation, a call to getCameraPosition() returns an intermediate location of the camera.

Parameters
update The change that should be applied to the camera.
callback The callback to invoke from the main thread when the animation stops. If the animation completes normally, onFinish() is called; otherwise, onCancel() is called. Do not update or animate the camera from within onCancel().

public final void animateCamera (CameraUpdate update)

Animates the movement of the camera from the current position to the position defined in the update. During the animation, a call to getCameraPosition() returns an intermediate location of the camera.

See CameraUpdateFactory for a set of updates.

Parameters
update The change that should be applied to the camera.

public final void clear ()

Removes all markers, overlays, and polylines from the map.

public final CameraPosition getCameraPosition ()

Gets the current position of the camera.

The CameraPosition returned is a snapshot of the current position, and will not automatically update when the camera moves.

Returns
  • The current position of the Camera.

public final int getMapType ()

Gets the type of map that's currently displayed. See MAP_TYPE_NORMAL, MAP_TYPE_SATELLITE, MAP_TYPE_TERRAIN for possible values.

Returns
  • The map type.

public final float getMaxZoomLevel ()

Returns the maximum zoom level for the current camera position. This takes into account what map type is currently being used, e.g., satellite or terrain may have a lower max zoom level than the base map tiles.

Returns
  • The maximum zoom level available at the current camera position.

public final float getMinZoomLevel ()

Returns the minimum zoom level. This is the same for every location (unlike the maximum zoom level) but may vary between devices and map sizes.

Returns
  • The minimum zoom level available.

public final Location getMyLocation ()

Returns the currently displayed user location, or null if there is no location data available.

Returns
Throws
IllegalStateException if the my-location layer is not enabled.

public final Projection getProjection ()

Returns a Projection object that you can use to convert between screen coordinates and latitude/longitude coordinates.

The Projection returned is a snapshot of the current projection, and will not automatically update when the camera moves. As this operation is expensive, you should get the projection only once per screen. Google Maps uses the Mercator projection to create its maps from geographic data and convert points on the map into geographic coordinates.

Returns

public final UiSettings getUiSettings ()

Gets the user interface settings for the map.

Returns

public final boolean isIndoorEnabled ()

Gets whether indoor maps are currently enabled.

Returns
  • true if indoor maps are enabled; false if indoor maps are disabled;

public final boolean isMyLocationEnabled ()

Gets the status of the my-location layer.

Returns
  • True if the my-location layer is enabled, false otherwise.

public final boolean isTrafficEnabled ()

Checks whether the map is drawing traffic data. This is subject to the availability of traffic data.

Returns
  • True if traffic data is enabled, false otherwise.

public final void moveCamera (CameraUpdate update)

Repositions the camera according to the instructions defined in the update. The move is instantaneous, and a subsequent getCameraPosition() will reflect the new position. See CameraUpdateFactory for a set of updates.

Parameters
update The change that should be applied to the camera.

public final boolean setIndoorEnabled (boolean enabled)

Sets whether indoor maps should be enabled. Currently, indoor maps can only be shown on one map at a time and by default, this is the first map added to your application. To enable indoor maps on another map, you must first disable indoor maps on the original map. If you try to enable indoor maps when it is enabled on another map, nothing will happen and this will return false. When Indoor is not enabled for a map, all methods related to indoor will return null, or false.

Parameters
enabled true to try to enable indoor maps; false to disable indoor maps.
Returns
  • whether it was possible to enable indoor maps.

public final void setInfoWindowAdapter (GoogleMap.InfoWindowAdapter adapter)

Sets a custom renderer for the contents of info windows.

Like the map's event listeners, this state is not serialized with the map. If the map gets re-created (e.g., due to a configuration change), you must ensure that you call this method again in order to preserve the customization.

Parameters
adapter The adapter to use for info window contents, or null to use the default content rendering in info windows.

public final void setLocationSource (LocationSource source)

Replaces the location source of the my-location layer.

Parameters
source A location source to use in the my-location layer. Set to null to use the default location source.

public final void setMapType (int type)

Sets the type of map tiles that should be displayed. The allowable values are:

Parameters
type The type of map to display.

public final void setMyLocationEnabled (boolean enabled)

Enables or disables the my-location layer.

While enabled, the my-location layer continuously draws an indication of a user's current location and bearing, and displays UI controls that allow a user to interact with their location (for example, to enable or disable camera tracking of their location and bearing).

Parameters
enabled True to enable; false to disable.

public final void setOnCameraChangeListener (GoogleMap.OnCameraChangeListener listener)

Sets a callback that's invoked when the camera changes.

Parameters
listener The callback that's invoked when the camera changes. To unset the callback, use null.

public final void setOnInfoWindowClickListener (GoogleMap.OnInfoWindowClickListener listener)

Sets a callback that's invoked when a marker info window is clicked.

Parameters
listener The callback that's invoked when a marker info window is clicked. To unset the callback, use null.

public final void setOnMapClickListener (GoogleMap.OnMapClickListener listener)

Sets a callback that's invoked when the map is tapped.

Parameters
listener The callback that's invoked when the map is tapped. To unset the callback, use null.

public final void setOnMapLongClickListener (GoogleMap.OnMapLongClickListener listener)

Sets a callback that's invoked when the map is long pressed.

Parameters
listener The callback that's invoked when the map is long pressed. To unset the callback, use null.

public final void setOnMarkerClickListener (GoogleMap.OnMarkerClickListener listener)

Sets a callback that's invoked when a marker is clicked.

Parameters
listener The callback that's invoked when a marker is clicked. To unset the callback, use null.

public final void setOnMarkerDragListener (GoogleMap.OnMarkerDragListener listener)

Sets a callback that's invoked when a marker is dragged.

Parameters
listener The callback that's invoked on marker drag events. To unset the callback, use null.

public final void setOnMyLocationChangeListener (GoogleMap.OnMyLocationChangeListener listener)

Sets a callback that's invoked when the my location dot changes location.

Parameters
listener The callback that's invoked when the my location dot changes.

public final void setTrafficEnabled (boolean enabled)

Toggles the traffic layer on or off.

public final void stopAnimation ()

Stops the camera animation if there is one in progress. When the method is called, the camera stops moving immediately and remains in that position.