java.lang.Object | |
↳ | com.google.android.gms.maps.GoogleMap |
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.
To get started, read the Google Maps Android API v2 developer guide.
Nested Classes | |||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
GoogleMap.CancelableCallback | A callback interface for reporting when a task is complete or cancelled. | ||||||||||||||||||||||||||||||||
GoogleMap.InfoWindowAdapter | Provides views for customized rendering of info windows. | ||||||||||||||||||||||||||||||||
GoogleMap.OnCameraChangeListener | Defines signatures for methods that are called when the camera changes position. | ||||||||||||||||||||||||||||||||
GoogleMap.OnInfoWindowClickListener | Callback interface for click/tap events on a marker's info window. | ||||||||||||||||||||||||||||||||
GoogleMap.OnMapClickListener | Callback interface for when the user taps on the map. | ||||||||||||||||||||||||||||||||
GoogleMap.OnMapLoadedCallback | Callback interface for when the map has finished rendering. | ||||||||||||||||||||||||||||||||
GoogleMap.OnMapLongClickListener | Callback interface for when the user long presses on the map. | ||||||||||||||||||||||||||||||||
GoogleMap.OnMarkerClickListener | Defines signatures for methods that are called when a marker is clicked or tapped. | ||||||||||||||||||||||||||||||||
GoogleMap.OnMarkerDragListener | Callback interface for drag events on markers. | ||||||||||||||||||||||||||||||||
GoogleMap.OnMyLocationButtonClickListener | Callback interface for when the My Location button is clicked. | ||||||||||||||||||||||||||||||||
GoogleMap.OnMyLocationChangeListener |
This interface is deprecated.
use LocationClient instead.
LocationClient provides improved location finding and power usage and is used by the
"My Location" blue dot. See the MyLocationDemoActivity in the sample applications folder
for example example code, or the
Location Developer Guide.
|
||||||||||||||||||||||||||||||||
GoogleMap.SnapshotReadyCallback | Callback interface to notify when the snapshot has been taken. |
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Add a circle to this map.
| |||||||||||
Adds an image to this map.
| |||||||||||
Adds a marker to this map.
| |||||||||||
Adds a polygon to this map.
| |||||||||||
Adds a polyline to this map.
| |||||||||||
Adds a tile overlay to this map.
| |||||||||||
Moves the map according to the update with an animation over a specified duration, and calls
an optional callback on completion.
| |||||||||||
Animates the movement of the camera from the current position to the position defined in the
update and calls an optional callback on completion.
| |||||||||||
Animates the movement of the camera from the current position to the position defined in the
update.
| |||||||||||
Removes all markers, polylines, polygons, overlays, etc from the map.
| |||||||||||
Gets the current position of the camera.
| |||||||||||
Gets the type of map that's currently displayed.
| |||||||||||
Returns the maximum zoom level for the current camera position.
| |||||||||||
Returns the minimum zoom level.
| |||||||||||
This method is deprecated.
use
LocationClient instead.
LocationClient provides improved location finding and power usage and is used by the
"My Location" blue dot. See the MyLocationDemoActivity in the sample applications folder
for example example code, or the
Location Developer Guide.
| |||||||||||
Returns a
Projection object that you can use to convert between screen coordinates
and latitude/longitude coordinates. | |||||||||||
Gets the user interface settings for the map.
| |||||||||||
Returns whether 3D buildings are enabled.
| |||||||||||
Gets whether indoor maps are currently enabled.
| |||||||||||
Gets the status of the my-location layer.
| |||||||||||
Checks whether the map is drawing traffic data.
| |||||||||||
Repositions the camera according to the instructions defined in the update.
| |||||||||||
Turns the 3D buildings layer on or off.
| |||||||||||
Sets whether indoor maps should be enabled.
| |||||||||||
Sets a custom renderer for the contents of info windows.
| |||||||||||
Replaces the location source of the my-location layer.
| |||||||||||
Sets the type of map tiles that should be displayed.
| |||||||||||
Enables or disables the my-location layer.
| |||||||||||
Sets a callback that's invoked when the camera changes.
| |||||||||||
Sets a callback that's invoked when a marker info window is clicked.
| |||||||||||
Sets a callback that's invoked when the map is tapped.
| |||||||||||
Sets a callback that is invoked when this map has finished rendering.
| |||||||||||
Sets a callback that's invoked when the map is long pressed.
| |||||||||||
Sets a callback that's invoked when a marker is clicked.
| |||||||||||
Sets a callback that's invoked when a marker is dragged.
| |||||||||||
Sets a callback that's invoked when the my location button is clicked.
| |||||||||||
This method is deprecated.
use
LocationClient instead.
LocationClient provides improved location finding and power usage and is used by the
"My Location" blue dot. See the MyLocationDemoActivity in the sample applications folder
for example example code, or the
Location Developer Guide.
| |||||||||||
Sets padding on the map.
| |||||||||||
Turns the traffic layer on or off.
| |||||||||||
Takes a snapshot of the map.
| |||||||||||
Takes a snapshot of the map.
| |||||||||||
Stops the camera animation if there is one in progress.
|
[Expand]
Inherited Methods | |||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Satellite maps with a transparent layer of major streets.
No base map tiles.
Basic maps.
Satellite maps with no labels.
Terrain maps.
Add a circle to this map.
options | A circle options object that defines how to render the Circle |
---|
Circle
object that is added to the map
Adds an image to this map.
options | A ground-overlay options object that defines how to render the overlay. Options must have an image (AnchoredBitmap) and position specified. |
---|
GroundOverlay
that was added to the map.IllegalArgumentException | if either the image or the position is unspecified in the 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.
options | A marker options object that defines how to render the marker. |
---|
Marker
that was added to the map.
Adds a polygon to this map.
options | A polygon options object that defines how to render the Polygon. |
---|
Polygon
object that is added to the map.
Adds a polyline to this map.
options | A polyline options object that defines how to render the Polyline. |
---|
Polyline
object that was added to the map.
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.
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. |
---|
TileOverlay
that was added to the map.IllegalArgumentException | if the TileProvider is unspecified in the options.
|
---|
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.
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. |
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.
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() .
|
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.
update | The change that should be applied to the camera. |
---|
Removes all markers, polylines, polygons, overlays, etc from the map.
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.
Gets the type of map that's currently displayed. See MAP_TYPE_NORMAL
,
MAP_TYPE_SATELLITE
, MAP_TYPE_TERRAIN
for possible values.
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 minimum zoom level. This is the same for every location (unlike the maximum zoom level) but may vary between devices and map sizes.
This method is deprecated.
use LocationClient
instead.
LocationClient provides improved location finding and power usage and is used by the
"My Location" blue dot. See the MyLocationDemoActivity in the sample applications folder
for example example code, or the
Location Developer Guide.
Returns the currently displayed user location, or null
if there is no location data
available.
user location
.IllegalStateException | if the my-location layer is not enabled. |
---|
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.
Projection
of the map in its current state.
Gets the user interface settings for the map.
UiSettings
for this map.
Returns whether 3D buildings are enabled.
Gets whether indoor maps are currently enabled.
true
if indoor maps are enabled; false
if indoor maps are disabled;
Gets the status of the my-location layer.
Checks whether the map is drawing traffic data. This is subject to the availability of traffic data.
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.
update | The change that should be applied to the camera. |
---|
Turns the 3D buildings layer on or off.
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
.
enabled | true to try to enable indoor maps; false to disable indoor
maps. |
---|
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.
adapter | The adapter to use for info window contents, or null to use the
default content rendering in info windows.
|
---|
Replaces the location source of the my-location layer.
source | A location source to use in the my-location layer. Set to null to use
the default location source.
|
---|
Sets the type of map tiles that should be displayed. The allowable values are:
MAP_TYPE_NORMAL
: Basic map with roads.MAP_TYPE_SATELLITE
: Satellite view with roads.MAP_TYPE_TERRAIN
: Terrain view without roads.type | The type of map to display. |
---|
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).
enabled | True to enable; false to disable. |
---|
Sets a callback that's invoked when the camera changes.
listener | The callback that's invoked when the camera changes. To unset the callback,
use null .
|
---|
Sets a callback that's invoked when a marker info window is clicked.
listener | The callback that's invoked when a marker info window is clicked. To unset
the callback, use null .
|
---|
Sets a callback that's invoked when the map is tapped.
listener | The callback that's invoked when the map is tapped. To unset the callback,
use null .
|
---|
Sets a callback that is invoked when this map has finished rendering. The callback will only be invoked once. If this method is called when the map is fully rendered, the callback will be invoked immediately. This event will not fire if the map never loads due to connectivity issues, or if the map is continuously changing and never completes loading due to the user constantly interacting with the map.
callback | The callback invoked when the map has finished rendering. To unset the
callback, use null .
|
---|
Sets a callback that's invoked when the map is long pressed.
listener | The callback that's invoked when the map is long pressed. To unset the
callback, use null .
|
---|
Sets a callback that's invoked when a marker is clicked.
listener | The callback that's invoked when a marker is clicked. To unset the callback,
use null .
|
---|
Sets a callback that's invoked when a marker is dragged.
listener | The callback that's invoked on marker drag events. To unset the callback, use
null .
|
---|
Sets a callback that's invoked when the my location button is clicked.
If the listener
returns true
, the event is consumed and the default
behavior will not occur. If it returns false
, the default behavior will occur (i.e.
The camera moves such that it is centered on the user's location).
listener | The callback that's invoked when the My Location button is clicked. |
---|
This method is deprecated.
use LocationClient
instead.
LocationClient provides improved location finding and power usage and is used by the
"My Location" blue dot. See the MyLocationDemoActivity in the sample applications folder
for example example code, or the
Location Developer Guide.
Sets a callback that's invoked when the My Location dot changes location.
listener | The callback that's invoked when the My Location dot changes. |
---|
Sets padding on the map.
This method allows you to define a visible region on the map, to signal to the map that portions of the map around the edges may be obscured, by setting padding on each of the four edges of the map. Map functions will be adapted to the padding. For example, the zoom controls, compass, copyright notices and Google logo will be moved to fit inside the defined region, camera movements will be relative to the center of the visible region, etc.
left | the number of pixels of padding to be added on the left of the map. |
---|---|
top | the number of pixels of padding to be added on the top of the map. |
right | the number of pixels of padding to be added on the right of the map. |
bottom | the number of pixels of padding to be added on the bottom of the map. |
Turns the traffic layer on or off.
Takes a snapshot of the map.
This method is equivalent to snapshot(SnapshotReadyCallback)
but lets you
provide a preallocated Bitmap
. If the bitmap does not match the current dimensions of
the map, another bitmap will be allocated that fits the map's dimensions.
Although in most cases the object passed by the callback method is the same as the one given in the parameter to this method, in some cases the returned object can be different (e.g., if the view's dimensions have changed by the time the snapshot is actually taken). Thus, you should only trust the content of the bitmap passed by the callback method.
callback | Callback method invoked when the snapshot is taken. |
---|---|
bitmap | A preallocated bitmap. If null , behaves like
snapshot(SnapshotReadyCallback) .
|
Takes a snapshot of the map.
You can use snapshots within your application when an interactive
map would be difficult, or impossible, to use. For example, images
produced with the snapshot()
method can be used to display a
thumbnail of the map in your app, or a snapshot in the notification
center.
Note: Images of the map must not be transmitted to your servers, or otherwise used outside of the application. If you need to send a map to another application or user, send data that allows them to reconstruct the map for the new user instead of a snapshot.
callback | Callback method invoked when the snapshot is taken. |
---|
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.