Skip to content

Marker

Markers are point annotations that can be placed on the map at specific geographic locations. They support custom icons, interactions, and animations.

For a small number of markers, you can specify options directly. Specifying an id helps prevent unnecessary recomposition.

@Composable
fun MapViewScope.Marker(
position: GeoPointInterface,
clickable: Boolean = true,
draggable: Boolean = false,
icon: MarkerIconInterface? = null,
extra: Serializable? = null,
id: String? = null,
onClick: OnMarkerEventHandler? = null,
onDragStart: OnMarkerEventHandler? = null,
onDrag: OnMarkerEventHandler? = null,
onDragEnd: OnMarkerEventHandler? = null,
onAnimateStart: OnMarkerEventHandler? = null,
onAnimateEnd: OnMarkerEventHandler? = null,
)
  • position: Geographic coordinates (GeoPointInterface)
  • clickable: Whether the marker responds to clicks (default: true)
  • draggable: Whether the marker can be dragged (default: false)
  • icon: Custom icon for the marker (MarkerIconInterface?)
  • extra: Additional data attached to the marker (Serializable?)
  • id: Unique identifier for the marker (String?)- onClick: Called when the marker is clicked
  • onDragStart: Called when the marker begins dragging
  • onDrag: Called while the marker is being dragged
  • onDragEnd: Called when the marker’s drag ends
  • onAnimateStart: Called when animate() begins
  • onAnimateEnd: Called when animate() finishes

Standard marker with customizable appearance:

DefaultIcon(
scale: Float = 1.0f,
label: String? = null,
fillColor: Color = Color.Red,
strokeColor: Color = Color.Black,
strokeWidth: Dp = 1.dp,
labelTextColor: Color = Color.White,
labelStrokeColor: Color? = null,
debug: Boolean = false
)

Marker using a drawable resource as background:

DrawableDefaultIcon(
backgroundDrawable: Drawable,
scale: Float = 1.0f,
strokeColor: Color? = null,
strokeWidth: Dp = 1.dp
)

Marker using a custom drawable image:

ImageIcon(
drawable: Drawable,
anchor: Offset = Offset(0.5f, 0.5f),
debug: Boolean = false
)
// Replace MapView with your chosen map provider, such as GoogleMapView, MapboxMapView
MapView(state = mapViewState) {
Marker(
position = GeoPoint.fromLatLong(37.7749, -122.4194),
extra = "San Francisco",
id = "san-francisco-marker"
)
}
// Replace MapView with your chosen map provider, such as GoogleMapView, MapboxMapView
MapView(state = mapViewState) {
Marker(
position = GeoPoint.fromLatLong(37.7749, -122.4194),
icon = DefaultIcon(
scale = 1.5f,
label = "SF",
fillColor = Color.Blue,
strokeColor = Color.White,
strokeWidth = 2.dp
),
extra = "San Francisco with custom icon",
id = "custom-sf-marker"
)
}
@Composable
fun DraggableMarkerExample() {
var markerPosition by remember {
mutableStateOf(GeoPoint.fromLatLong(37.7749, -122.4194))
}
// Replace MapView with your chosen map provider, such as GoogleMapView, MapboxMapView
MapView(
state = mapViewState
) {
Marker(
position = markerPosition,
draggable = true,
icon = DefaultIcon(
label = "Drag me",
fillColor = Color.Green
),
onDrag = { markerState ->
markerPosition = markerState.position
}
)
}
}
// Replace MapView with your chosen map provider, such as GoogleMapView, MapboxMapView
MapView(state = mapViewState) {
// Default icon with different scales
Marker(
position = GeoPoint.fromLatLong(37.7749, -122.4194),
icon = DefaultIcon(scale = 0.7f, label = "Small")
)
Marker(
position = GeoPoint.fromLatLong(37.7849, -122.4094),
icon = DefaultIcon(scale = 1.0f, label = "Normal")
)
Marker(
position = GeoPoint.fromLatLong(37.7949, -122.3994),
icon = DefaultIcon(scale = 1.4f, label = "Large")
)
// Custom colored marker
Marker(
position = GeoPoint.fromLatLong(37.7649, -122.4294),
icon = DefaultIcon(
fillColor = Color.Yellow,
strokeColor = Color.Black,
strokeWidth = 2.dp,
label = "Custom"
)
)
// Drawable icon marker
val context = LocalContext.current
AppCompatResources.getDrawable(context, R.drawable.custom_icon)?.let { drawable ->
Marker(
position = GeoPoint.fromLatLong(37.7549, -122.4394),
icon = DrawableDefaultIcon(
backgroundDrawable = drawable,
scale = 1.2f
)
)
}
}
  • Drop - Animation where the marker moves from the top of the screen to the position
  • Bounce - Marker moves from the top of the screen to the position, then bounces
marker bounce and drop animation preview