Member-only story
Clustering With Maps Compose For Android
Bridging the maps-util library with Jetpack Compose
Ever since the Google team released their maps library for Jetpack Compose, they’ve strived to catch up with what the older maps library offers. I‘ve explored what you could do with Map Compose in a former article, and I was left with one key issue at hand: clustering was not supported yet.
Clustering matters as soon as you want to display many points of interest (POI) within the same region. Instead of cluttering your map with thousands of points overlapping each other, you can regroup them under a single item: a cluster. Once the zoomed region reduces enough to show them all, the cluster would fade to reveal those points instead.
Needless to say, I was disappointed to discover its lack of support. Yet, the library barely made it to its first stable release, and they had to prioritize. Especially since the current cluster implementation lurks within a maps-util library that doesn’t fit with the Compose paradigm.
Fast-forwarding a year later from 1.0.0, we can’t say the library completely supports clustering. But it’s no longer a blocker either.
Bridging the Maps Util Library
From what we’ve seen, the team was left with two options to make clustering compatible:
- bring their internal solution that better suits Compose.
- bridge with the maps-util library.
Although the first option outwins the second (for performance and integration reasons), that entails a significant development to bring its full support. And as a result, would postpone its release to an unknown date.
The team focused on the second solution to unlock developers. Although far from ideal, it acts as an escape hatch until proper clustering with Compose would come to light.
Bridging the maps-util library means exposing a GoogleMap
instance from the Compose library that was so far internal. We’ll inject this instance into a ClusterManager
(from the maps-util library) that will take care of the rest for us. For more information, you can read this open issue detailing the feature request.
Beware that this instance…