目录

Marker

Class Info

public class Marker

Icon placed at the specified position on the map. An instance of this type will be returned when the addMarker method in the HuaweiMap class is called.

Public Method Summary

Qualifier and Type

Method Name and Description

float

getAlpha()

Obtains the transparency of a marker.

LatLng

getPosition()

Obtains the position of a marker.

float

getRotation()

Obtains the rotation angle of a marker.

String

getSnippet()

Obtains the text snippet of a marker.

Object

getTag()

Obtains the tag attribute of a marker.

String

getTitle()

Obtains the title of a marker.

float

getZIndex()

Obtains the z-index of a marker.

void

hideInfoWindow()

Hides the information window that is displayed for a marker.

boolean

isClickable()

Checks whether a marker is clickable.

boolean

isClusterable()

Checks whether a marker can be clustered.

boolean

isDraggable()

Checks whether users can long press a marker to drag it.

boolean

isFlat()

Checks whether a marker is flatly attached to the map.

boolean

isInfoWindowShown()

Checks whether an information window is currently displayed for a marker.

boolean

isVisible()

Checks whether a marker is visible.

void

remove()

Removes a marker from the map.

void

setAlpha(float alpha)

Sets the transparency of a marker.

void

setAnchor(float anchorU, float anchorV)

Sets the anchor point of a marker.

CAUTION:

This method has been deprecated. To set an anchor point, call setMarkerAnchor.

void

setAnimation(Animation animation)

Sets the animation of a marker.

void

setClickable(boolean clickable)

Sets whether a marker is clickable.

void

setDraggable(boolean draggable)

Sets whether users can long press a marker to drag it.

void

setFlat(boolean flat)

Sets whether a marker is flatly attached to the map.

void

setIcon(BitmapDescriptor iconDescriptor)

Sets the icon of a marker.

void

setInfoWindowAnchor(float anchorU, float anchorV)

Sets the anchor point of a marker's information window. The coordinate system used is the same as that of the anchor point of a marker. By default, the top-middle point of the marker image is used as the anchor point.

void

setMarkerAnchor(float anchorU, float anchorV)

Sets the anchor point of a marker.

void

setPosition(LatLng latLng)

Sets the position coordinates of a marker.

void

setRotation(float rotation)

Sets the rotation angle of a marker, that is, the angle in which the marker rotates around the anchor point clockwise. The rotation axis is perpendicular to the marker.

void

setSnippet(String snippet)

Sets the text snippet of a marker. If null is passed, no text snippet will be displayed.

void

setTag(Object tag)

Sets the tag attribute of a marker. If null is passed, the tag attribute will be cleared.

void

setTitle(String title)

Sets the title of a marker. By default, the title is empty.

void

setVisible(boolean visible)

Sets whether a marker is visible.

void

setZIndex(float zIndex)

Sets the z-index of a marker.

void

showInfoWindow()

Displays the information window for a marker.

void

startAnimation()

Starts the animation of a marker.

Public Methods

[h2]getAlpha

Method

public float getAlpha()

Obtains the transparency of a marker.

Returns

Type

Description

float

Transparency of a marker. The value ranges from 0 to 1.

[h2]getPosition

Method

public final LatLng getPosition()

Obtains the position of a marker.

Returns

Type

Description

LatLng

Marker position.

[h2]getRotation

Method

public final float getRotation()

Obtains the rotation angle of a marker.

Returns

Type

Description

float

Rotation angle of a marker.

[h2]getSnippet

Method

public final String getSnippet()

Obtains the text snippet of a marker.

Returns

Type

Description

String

Text snippet of a marker.

[h2]getTag

Method

public Object getTag()

Obtains the tag attribute (if it has been set) of a marker.

Returns

Type

Description

Object

Object if a tag has been set; null otherwise.

[h2]getTitle

Method

public final String getTitle()

Obtains the title of a marker.

Returns

Type

Description

String

Title string of a marker.

[h2]getZIndex

Method

public float getZIndex()

Obtains the z-index of a marker.

Returns

Type

Description

float

Z-index, which indicates the overlapping order of a marker.

[h2]hideInfoWindow

Method

public final void hideInfoWindow()

Hides the information window that is displayed for a marker. This method is invalid for invisible markers.

[h2]isClickable

Method

public boolean isClickable()

Checks whether a marker is clickable.

Returns

Type

Description

boolean

true if a marker is clickable; false otherwise.

[h2]isClusterable

Method

public boolean isClusterable()

Checks whether a marker can be clustered.

Returns

Type

Description

boolean

true if a marker can be clustered; false otherwise.

[h2]isDraggable

Method

public final boolean isDraggable()

Checks whether users can long press a marker to drag it.

Returns

Type

Description

boolean

true if users can long press a marker to drag it; false otherwise.

[h2]isFlat

Method

public final boolean isFlat()

Checks whether a marker is flatly attached to the map.

Returns

Type

Description

boolean

true if a marker is flatly attached to the map; false otherwise.

[h2]isInfoWindowShown

Method

public final boolean isInfoWindowShown()

Checks whether an information window is currently displayed for a marker. This method will not consider whether the information window is actually visible on the screen.

Returns

Type

Description

boolean

true if an information window is currently displayed for a marker; false otherwise.

[h2]isVisible

Method

public final boolean isVisible()

Checks whether a marker is visible.

Returns

Type

Description

boolean

true if a marker is visible; false otherwise.

[h2]remove

Method

public final void remove()

Removes a marker from the map.

[h2]setAlpha

Method

public final void setAlpha(float alpha)

Sets the transparency of a marker.

Parameters

Name

Description

alpha

Transparency of a marker. The value ranges from 0 to 1.

  • 0: transparent
  • 1: opaque

The default value is 1.

[h2]setAnchor

This method has been deprecated. To set an anchor point, call setMarkerAnchor.

Method

public final void setAnchor(float anchorU, float anchorV)

Sets the anchor point of a marker. Since of the values of U and V are fixed, this method always sets the anchor point to the bottom of the marker icon.

Parameters

Name

Description

anchorU

Horizontal coordinate of the anchor point of a marker. The value ranges from 0 to 1, expressed in a proportion of the marker image width. The default value is 0.5.

anchorV

Vertical coordinate of the anchor point of a marker. The value ranges from 0 to 1, expressed in a proportion of the marker image height. The default value is 0.5.

[h2]setAnimation

Method

public void setAnimation(Animation animation)

Sets the animation of a marker.

Parameters

Name

Description

animation

Animation.

[h2]setClickable

Method

public void setClickable(boolean clickable)

Sets whether a marker is clickable.

Parameters

Name

Description

clickable

Indicates whether a marker is clickable.

  • true (default): yes
  • false: no

[h2]setDraggable

Method

public final void setDraggable(boolean draggable)

Sets whether users can long press a marker to drag it.

Parameters

Name

Description

draggable

Indicates whether users can long press a marker to drag it.

  • true: yes
  • false: no

The default value is false.

[h2]setFlat

Method

public final void setFlat(boolean flat)

Sets whether to flatly attach a marker to the map. If the marker is flatly attached to the map, it will stay on the map when the camera rotates or tilts. Different from a ground overlay (GroundOverlay), the marker will remain the same size when the camera zooms in or out. If the marker faces the camera, it will always be drawn facing the camera and rotates or tilts with the camera.

Parameters

Name

Description

flat

Indicates whether to flatly attach a marker to the map.

  • true: yes
  • false: no

The default value is false.

[h2]setIcon

Method

public final void setIcon(BitmapDescriptor iconDescriptor)

Sets the icon of a marker. If null is passed, the default marker will be used.

Parameters

Name

Description

iconDescriptor

Object containing an icon.

[h2]setInfoWindowAnchor

Method

public final void setInfoWindowAnchor(float anchorU, float anchorV)

Sets the anchor point of a marker's information window. The coordinate system used is the same as that of the anchor point of a marker. By default, the top-middle point of the marker image is used as the anchor point. For details, please refer to setMarkerAnchor(float anchorU, float anchorV).

Parameters

Name

Description

anchorU

Horizontal coordinate of the anchor point of an information window. The recommended value ranges from 0 to 1, expressed in a proportion of the information window width.

anchorV

Vertical coordinate of the anchor point of an information window. The recommended value ranges from 0 to 1, expressed in a proportion of the information window height.

[h2]setMarkerAnchor

Method

public final void setMarkerAnchor(float anchorU, float anchorV)

Sets the anchor point of a marker. The anchor point is used to anchor a marker image to the map. The coordinates (0, 0), (1, 0), (0, 1), and (1, 1) respectively indicate the top-left, top-right, bottom-left, and bottom-right corners of the marker image. The following figure shows a marker's anchor point X whose coordinates are (0.5, 0.3).

Parameters

Name

Description

anchorU

Horizontal coordinate of the anchor point of a marker. The recommended value ranges from 0 to 1, expressed in a proportion of the marker image width. The default value is 0.5.

anchorV

Vertical coordinate of the anchor point of a marker. The recommended value ranges from 0 to 1, expressed in a proportion of the marker image height. The default value is 1.

[h2]setPosition

Method

public final void setPosition(LatLng latLng)

Sets the position coordinates of a marker.

Parameters

Name

Description

latLng

Position coordinates of a marker.

Throws

Name

Description

IllegalArgumentException

If the passed latlng is empty.

[h2]setRotation

Method

public final void setRotation(float rotation)

Sets the rotation angle of a marker, that is, the angle in which the marker rotates around the anchor point clockwise. The rotation axis is perpendicular to the marker. By default, the marker is north aligned, and the rotation angle is 0 degrees.

Parameters

Name

Description

rotation

Rotation angle of a marker. The default value is 0.

[h2]setSnippet

Method

public final void setSnippet(String snippet)

Sets the text snippet of a marker. If null is passed, no text snippet will be displayed.

Parameters

Name

Description

snippet

Text snippet of a marker.

[h2]setTag

Method

public final void setTag(Object tag)

Sets the tag attribute of a marker. The tag attribute can be any object. If null is passed, the tag attribute will be cleared. If you no longer use the tag attribute, call setTag(null) to clear it to prevent memory leakage from occurring on the app.

Parameters

Name

Description

tag

Tag of a marker.

[h2]setTitle

Method

public final void setTitle(String title)

Sets the title of a marker. By default, the title is empty.

Parameters

Name

Description

title

Title string. If this parameter is set to null, the existing title will be cleared.

[h2]setVisible

Method

public final void setVisible(boolean visible)

Sets whether a marker is visible.

Parameters

Name

Description

visible

Indicates whether a marker is visible.

  • true: yes
  • false: no

The default value is true.

[h2]setZIndex

Method

public final void setZIndex(float zIndex)

Sets the z-index of a marker. The z-index indicates the overlapping order of a marker. A marker with a larger z-index overlaps that with a smaller z-index. Markers with the same z-index overlap each other by the order in which they are added.

Parameters

Name

Description

zIndex

Z-index, which indicates the overlapping order of a marker. By default, the z-index is 0.

CAUTION:

If a marker is tapped, the marker will be place at the top and its z-index will be set to 3.4028235E38.

[h2]showInfoWindow

Method

public final void showInfoWindow()

Displays the information window for a marker.

[h2]startAnimation

Method

public void startAnimation()

Starts the animation of a marker.