Skip to content

Marker Clustering

The android-marker-clustering module provides automatic marker clustering for MapConductor. It groups nearby markers into clusters as you zoom out, and expands them back into individual markers as you zoom in. Works with any map provider (Google Maps, MapLibre, Mapbox, ArcGIS, HERE, etc.).

dependencies {
implementation(platform("com.mapconductor:mapconductor-bom:1.1.3"))
implementation("com.mapconductor:core")
implementation("com.mapconductor:marker-clustering")
// Choose your map provider
implementation("com.mapconductor:for-googlemaps")
}

Wrap your markers with MarkerClusterGroup inside any XxxMapView content block:

val markerStates: List<MarkerState> = remember { buildMarkerList() }
XxxMapView(...) {
MarkerClusterGroup<ActualMarker>(
state = remember { MarkerClusterGroupState() },
markers = markerStates,
)
}

Replace ActualMarker with the map-specific marker type for your provider (e.g. Marker for Google Maps, Symbol for MapLibre).

Use MarkerClusterGroupState to configure clustering behavior:

val clusterState = remember {
MarkerClusterGroupState<ActualMarker>(
clusterRadiusPx = 50.0,
minClusterSize = 2,
onClusterClick = { cluster ->
// handle cluster tap
},
)
}
XxxMapView(...) {
MarkerClusterGroup(
state = clusterState,
markers = markerStates,
)
}

Provide a clusterIconProvider lambda to render a custom icon for each cluster:

val clusterState = remember {
MarkerClusterGroupState<ActualMarker>(
clusterIconProvider = { count ->
DefaultMarkerIcon(
fillColor = Color.Blue,
label = count.toString(),
labelTextColor = Color.White,
)
},
)
}

Add extra overlays alongside clustered markers using the content lambda:

XxxMapView(...) {
MarkerClusterGroup(
state = clusterState,
markers = markerStates,
) {
// Additional composables rendered alongside the cluster group
Circle(circleState)
}
}
PropertyTypeDefaultDescription
clusterRadiusPxDouble50.0Pixel radius within which markers are clustered
minClusterSizeInt2Minimum number of markers to form a cluster
expandMarginDoubleExtra margin when expanding clusters
clusterIconProvider(Int) -> MarkerIconInterfaceDefault circle badgeReturns an icon for the given cluster size
onClusterClick((MarkerCluster) -> Unit)?nullCalled when a cluster marker is tapped
enableZoomAnimationBooleanfalseAnimate markers on zoom change
enablePanAnimationBooleanfalseAnimate markers on pan
zoomAnimationDurationMillisLongDuration of zoom animation
cameraIdleDebounceMillisLongDebounce delay before re-clustering after camera stops