public class Marker extends Annotation
IconFactory
to generate an
Icon
using a provided image. Markers are added to the map by first giving a
LatLng
and using MapboxMap.addMarker(MarkerOptions)
. The marker icon will be
centered at this position so it is common to add padding to the icon image before usage.
If more customization is needed, we offer MarkerView
which places a View
on top
of the map at a geographical location.
Markers are designed to be interactive. They receive click events by default, and are often used
with event listeners to bring up info windows. An InfoWindow
is displayed by default when
either a title or snippet is provided.
mapboxMap, mapView
Constructor and Description |
---|
Marker(BaseMarkerOptions baseMarkerOptions)
Creates a instance of
Marker using the builder of Marker. |
Modifier and Type | Method and Description |
---|---|
Icon |
getIcon()
Gets the
Icon currently used for the marker. |
InfoWindow |
getInfoWindow()
Gets the
InfoWindow the marker is using. |
LatLng |
getPosition()
Returns the position of the marker.
|
java.lang.String |
getSnippet()
Gets the snippet of the marker.
|
java.lang.String |
getTitle()
Gets the snippet of the marker.
|
void |
hideInfoWindow()
Do not use this method, used internally by the SDK.
|
boolean |
isInfoWindowShown()
Do not use this method, used internally by the SDK.
|
void |
setIcon(Icon icon)
Sets the icon of the marker.
|
void |
setPosition(LatLng position)
Sets the location of the marker.
|
void |
setRightOffsetPixels(int rightOffsetPixels)
Do not use this method, used internally by the SDK.
|
void |
setSnippet(java.lang.String snippet)
Sets the snippet of the marker.
|
void |
setTitle(java.lang.String title)
Sets the title of the marker.
|
void |
setTopOffsetPixels(int topOffsetPixels)
Do not use this method, used internally by the SDK.
|
InfoWindow |
showInfoWindow(MapboxMap mapboxMap,
MapView mapView)
Do not use this method, used internally by the SDK.
|
java.lang.String |
toString()
Returns a String with the marker position.
|
compareTo, equals, getId, getMapboxMap, getMapView, hashCode, remove, setId, setMapboxMap, setMapView
public Marker(BaseMarkerOptions baseMarkerOptions)
Marker
using the builder of Marker.baseMarkerOptions
- The builder used to construct the Marker.public LatLng getPosition()
LatLng
object specifying the marker's current position.public java.lang.String getSnippet()
public java.lang.String getTitle()
public void hideInfoWindow()
public boolean isInfoWindowShown()
public void setPosition(LatLng position)
position
- A LatLng
defining the marker position.public void setSnippet(java.lang.String snippet)
snippet
- A String used in the marker info window. If null
, the snippet is
cleared.public void setIcon(@Nullable Icon icon)
icon
- The Icon
to be used as Marker imagepublic Icon getIcon()
Icon
currently used for the marker. If no Icon was set for the marker, the
default icon will be returned.Icon
the marker is using.public void setTitle(java.lang.String title)
title
- A String used in the marker info window. If null
, the title is
cleared.@Nullable public InfoWindow getInfoWindow()
InfoWindow
the marker is using. If the marker hasn't had an info window
defined, this will return null
.public InfoWindow showInfoWindow(@NonNull MapboxMap mapboxMap, @NonNull MapView mapView)
MapboxMap.selectMarker(Marker)
if you want to programmatically display the markers info window.mapboxMap
- The hosting mapbox map.mapView
- The hosting map view.public void setTopOffsetPixels(int topOffsetPixels)
topOffsetPixels
- the top offset pixels.public void setRightOffsetPixels(int rightOffsetPixels)
rightOffsetPixels
- the right offset pixels.public java.lang.String toString()
toString
in class java.lang.Object