Clustering

fun <T : ClusterItem> Clustering(items: Collection<T>, onClusterClick: (Cluster<T>) -> Boolean = { false }, onClusterItemClick: (T) -> Boolean = { false }, onClusterItemInfoWindowClick: (T) -> Unit = { }, onClusterItemInfoWindowLongClick: (T) -> Unit = { }, clusterContent: @Composable (Cluster<T>) -> Unit? = null, clusterItemContent: @Composable (T) -> Unit? = null)

Groups many items on a map based on zoom level.

Parameters

items

all items to show

onClusterClick

a lambda invoked when the user clicks a cluster of items

onClusterItemClick

a lambda invoked when the user clicks a non-clustered item

onClusterItemInfoWindowClick

a lambda invoked when the user clicks the info window of a non-clustered item

onClusterItemInfoWindowLongClick

a lambda invoked when the user long-clicks the info window of a non-clustered item

clusterContent

an optional Composable that is rendered for each Cluster.

clusterItemContent

an optional Composable that is rendered for each non-clustered item.


fun <T : ClusterItem> Clustering(items: Collection<T>, onClusterClick: (Cluster<T>) -> Boolean = { false }, onClusterItemClick: (T) -> Boolean = { false }, onClusterItemInfoWindowClick: (T) -> Unit = { }, onClusterItemInfoWindowLongClick: (T) -> Unit = { }, clusterContent: @Composable (Cluster<T>) -> Unit? = null, clusterItemContent: @Composable (T) -> Unit? = null, onClusterManager: (ClusterManager<T>) -> Unit? = null)

Groups many items on a map based on zoom level.

Parameters

items

all items to show

onClusterClick

a lambda invoked when the user clicks a cluster of items

onClusterItemClick

a lambda invoked when the user clicks a non-clustered item

onClusterItemInfoWindowClick

a lambda invoked when the user clicks the info window of a non-clustered item

onClusterItemInfoWindowLongClick

a lambda invoked when the user long-clicks the info window of a non-clustered item

clusterContent

an optional Composable that is rendered for each Cluster.

clusterItemContent

an optional Composable that is rendered for each non-clustered item.

onClusterManager

an optional lambda invoked with the clusterManager as a param when both the clusterManager and renderer are set up, allowing callers a customization hook.


fun <T : ClusterItem> Clustering(items: Collection<T>, clusterManager: ClusterManager<T>)

Groups many items on a map based on clusterManager.

Parameters

items

all items to show

clusterManager

a ClusterManager that can be used to specify the algorithm used by the rendering.


fun <T : ClusterItem> Clustering(items: Collection<T>, onClusterClick: (Cluster<T>) -> Boolean = { false }, onClusterItemClick: (T) -> Boolean = { false }, onClusterItemInfoWindowClick: (T) -> Unit = { }, onClusterItemInfoWindowLongClick: (T) -> Unit = { }, clusterContent: @Composable (Cluster<T>) -> Unit? = null, clusterItemContent: @Composable (T) -> Unit? = null, clusterRenderer: ClusterRenderer<T>? = null)

Deprecated

If clusterRenderer is specified, clusterContent and clusterItemContent are not used; use a function that takes ClusterManager as an argument instead.

Replace with

import com.google.maps.android.compose.clustering.Clustering
import androidx.compose.runtime.SideEffect
import com.google.maps.android.clustering.ClusterManager

            val clusterManager = rememberClusterManager<T>()
            LaunchedEffect(clusterManager, clusterRenderer) {
                clusterManager?.renderer = clusterRenderer
            }
            SideEffect {
                clusterManager ?: return@SideEffect
                clusterManager.setOnClusterClickListener(onClusterClick)
                clusterManager.setOnClusterItemClickListener(onClusterItemClick)
                clusterManager.setOnClusterItemInfoWindowClickListener(onClusterItemInfoWindowClick)
                clusterManager.setOnClusterItemInfoWindowLongClickListener(onClusterItemInfoWindowLongClick)
            }
            // Wait for renderer to apply before clustering
            if (clusterManager != null && clusterManager.renderer == clusterRenderer) {
                Clustering(
                    items = items,
                    clusterManager = clusterManager,
                )
            }
        

Groups many items on a map based on zoom level.

Parameters

items

all items to show

onClusterClick

a lambda invoked when the user clicks a cluster of items

onClusterItemClick

a lambda invoked when the user clicks a non-clustered item

onClusterItemInfoWindowClick

a lambda invoked when the user clicks the info window of a non-clustered item

onClusterItemInfoWindowLongClick

a lambda invoked when the user long-clicks the info window of a non-clustered item

clusterContent

an optional Composable that is rendered for each Cluster.

clusterItemContent

an optional Composable that is rendered for each non-clustered item.

clusterRenderer

an optional ClusterRenderer that can be used to specify the algorithm used by the rendering.