java.lang.Object | |
↳ | com.google.android.gms.maps.model.Marker |
An icon placed at a particular point on the map's surface. A marker icon is drawn oriented against the device's screen rather than the map's surface; i.e., it will not necessarily change orientation due to map rotations, tilting, or zooming.
A marker has the following properties:
LatLng
position of the marker. This
defaults to 50% from the left of the image and at the bottom of the image.LatLng
value for the marker's position on the map. You can change this value at
any time if you want to move the marker.defaultMarker(float)
.true
. You can
change this value at any time. The default is false
.false
. You can change this value at any time.GroundOverlay
. If the marker is a billboard, it will always be drawn facing the camera
and will rotate and tilt with the camera. The default is a billboard (false
)Object
associated with the marker. For example, the Object
can contain
data about what the marker represents. This is easier than storing a separate
Map<Marker, Object>
. As another example, you can associate a String
ID
corresponding to the ID from a data set. Google Maps Android API neither reads nor writes this
property.
Methods in this class must be called on the Android UI thread. If not, an
IllegalStateException
will be thrown at runtime.
GoogleMap map = ... // get a map.
// Add a marker at San Francisco.
Marker marker = map.addMarker(new MarkerOptions()
.position(new LatLng(37.7750, 122.4183))
.title("San Francisco")
.snippet("Population: 776733"));
For more information, read the Markers developer guide.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the alpha of the marker.
| |||||||||||
Gets this marker's id.
| |||||||||||
Returns the position of the marker.
| |||||||||||
Gets the rotation of the marker.
| |||||||||||
Gets the snippet of the marker.
| |||||||||||
Gets the tag for the marker.
| |||||||||||
Gets the title of the marker.
| |||||||||||
Returns the zIndex of the marker.
| |||||||||||
Hides the info window if it is shown from this marker.
| |||||||||||
Gets the draggability of the marker.
| |||||||||||
Gets the flat setting of the Marker.
| |||||||||||
Returns whether the info window is currently shown above this marker.
| |||||||||||
Gets the visibility setting of this marker.
| |||||||||||
Removes this marker from the map.
| |||||||||||
Sets the alpha (opacity) of the marker.
| |||||||||||
Sets the anchor point for the marker.
| |||||||||||
Sets the draggability of the marker.
| |||||||||||
Sets whether this marker should be flat against the map
true or a billboard facing
the camera false . | |||||||||||
Sets the icon for the marker.
| |||||||||||
Specifies the point in the marker image at which to anchor the info window when it is
displayed.
| |||||||||||
Sets the location of the marker.
| |||||||||||
Sets the rotation of the marker in degrees clockwise about the marker's anchor point.
| |||||||||||
Sets the snippet of the marker.
| |||||||||||
Sets the tag for the marker.
| |||||||||||
Sets the title of the marker.
| |||||||||||
Sets the visibility of this marker.
| |||||||||||
Sets the zIndex of the marker.
| |||||||||||
Shows the info window of this marker on the map, if this marker
isVisible() . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Parameters | |
---|---|
other |
Object
|
Returns | |
---|---|
boolean |
Gets the alpha of the marker.
Returns | |
---|---|
float |
the alpha of the marker in the range [0, 1]. |
Gets this marker's id. The id will be unique amongst all Markers on a map.
Returns | |
---|---|
String |
this marker's id. |
Gets the rotation of the marker.
Returns | |
---|---|
float |
the rotation of the marker in degrees clockwise from the default position. |
Gets the snippet of the marker.
Returns | |
---|---|
String |
A string containing the marker's snippet. |
Gets the tag for the marker.
Returns | |
---|---|
Object |
the tag if a tag was set with setTag ; null if no tag has been set.
|
Gets the title of the marker.
Returns | |
---|---|
String |
A string containing the marker's title. |
Returns the zIndex of the marker.
Returns | |
---|---|
float |
this marker's zIndex. |
Returns | |
---|---|
int |
Hides the info window if it is shown from this marker.
This method has no effect if this marker is not visible.
Gets the draggability of the marker. When a marker is draggable, it can be moved by the user by long pressing on the marker.
Returns | |
---|---|
boolean |
true if the marker is draggable; otherwise, returns false .
|
Gets the flat setting of the Marker.
Returns | |
---|---|
boolean |
true if the marker is flat against the map; false if the marker
should face the camera.
|
Returns whether the info window is currently shown above this marker. This does not consider whether or not the info window is actually visible on screen.
Returns | |
---|---|
boolean |
Gets the visibility setting of this marker. Note that this does not indicate whether the marker is within the screen's viewport. It indicates whether the marker will be drawn if it is contained in the screen's viewport.
Returns | |
---|---|
boolean |
this marker's visibility. |
Removes this marker from the map. After a marker has been removed, the behavior of all its methods is undefined.
Sets the alpha (opacity) of the marker. This is a value from 0 to 1, where 0 means the marker is completely transparent and 1 means the marker is completely opaque.
Parameters | |
---|---|
alpha |
float
|
Sets the anchor point for the marker.
The anchor specifies the point in the icon image that is anchored to the marker's position on the Earth's surface.
The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner. The anchoring point in a W x H image is the nearest discrete grid point in a (W + 1) x (H + 1) grid, obtained by scaling the then rounding. For example, in a 4 x 2 image, the anchor point (0.7, 0.6) resolves to the grid point at (3, 1).
*-----+-----+-----+-----* | | | | | | | | | | +-----+-----+-----+-----+ | | | X | | (U, V) = (0.7, 0.6) | | | | | *-----+-----+-----+-----* *-----+-----+-----+-----* | | | | | | | | | | +-----+-----+-----X-----+ (X, Y) = (3, 1) | | | | | | | | | | *-----+-----+-----+-----*
Parameters | |
---|---|
anchorU |
float :
u-coordinate of the anchor, as a ratio of the image width
(in the range [0, 1]). |
anchorV |
float :
v-coordinate of the anchor, as a ratio of the image height
(in the range [0, 1]).
|
Sets the draggability of the marker. When a marker is draggable, it can be moved by the user by long pressing on the marker.
Parameters | |
---|---|
draggable |
boolean
|
Sets whether this marker should be flat against the map true
or a billboard facing
the camera false
.
Parameters | |
---|---|
flat |
boolean
|
Sets the icon for the marker.
Parameters | |
---|---|
iconDescriptor |
BitmapDescriptor :
if null, the default marker is used.
|
Specifies the point in the marker image at which to anchor the info window when it is
displayed. This is specified in the same coordinate system as the anchor. See
setAnchor(float, float)
for more details. The default is the top middle of the
image.
Parameters | |
---|---|
anchorU |
float :
u-coordinate of the info window anchor, as a ratio of the image width (in the
range [0, 1]). |
anchorV |
float :
v-coordinate of the info window anchor, as a ratio of the image height (in the
range [0, 1]).
|
Sets the rotation of the marker in degrees clockwise about the marker's anchor point. The axis of rotation is perpendicular to the marker. A rotation of 0 corresponds to the default position of the marker.
Parameters | |
---|---|
rotation |
float
|
Sets the snippet of the marker.
Parameters | |
---|---|
snippet |
String :
if null, the snippet is cleared.
|
Sets the tag for the marker.
You can use this property to associate an arbitrary Object
with this marker. For
example, the Object
can contain data about what the marker represents. This is easier
than storing a separate Map<Marker, Object>
. As another example, you can associate a
String
ID corresponding to the ID from a data set. Google Maps Android API neither
reads nor writes this property. It is your responsibility to call setTag(null)
to
clear the tag when you no longer need it, to prevent memory leaks in your app.
Parameters | |
---|---|
tag |
Object :
if null, the tag is cleared.
|
Sets the title of the marker.
Parameters | |
---|---|
title |
String :
if null, the title is cleared.
|
Sets the visibility of this marker. If set to false
and an info window is currently
showing for this marker, this will hide the info window.
Parameters | |
---|---|
visible |
boolean
|
Sets the zIndex of the marker.
Parameters | |
---|---|
zIndex |
float
|
Shows the info window of this marker on the map, if this marker isVisible()
.
Throws | |
---|---|
IllegalArgumentException |
if marker is not on this map
|