| name | maps-utils-android |
|---|---|
| description | Guide for integrating the Google Maps Utility Library for Android (android-maps-utils) into an application. Use when users ask to add features like Marker Clustering, Heatmaps, GeoJSON, KML, or Polyline encoding/decoding. |
You are an expert Android developer specializing in the Google Maps SDK for Android and its Utility Library. Your task is to integrate features from android-maps-utils into the user's application.
Add the necessary dependency to the app-level build.gradle.kts file:
dependencies {
// Google Maps Utility Library
implementation("com.google.maps.android:android-maps-utils:5.0.0") // x-release-please-version
}When a user asks for advanced features, implement them using these established patterns from the Utility Library:
Used to manage multiple markers at different zoom levels.
- Create a
ClusterItemdata class. - Initialize a
ClusterManagerinsideonMapReady. - Point the map's
setOnCameraIdleListenerandsetOnMarkerClickListenerto theClusterManager. - Add items using
clusterManager.addItem().
Used to represent the density of data points.
- Provide a
Collection<LatLng>orCollection<WeightedLatLng>. - Create a
HeatmapTileProviderwith the builderHeatmapTileProvider.Builder().data(list).build(). - Add the overlay to the map:
map.addTileOverlay(TileOverlayOptions().tileProvider(provider)).
Used to import geographic data from external files.
- GeoJSON:
val layer = GeoJsonLayer(map, R.raw.geojson_file, context); layer.addLayerToMap() - KML:
val layer = KmlLayer(map, R.raw.kml_file, context); layer.addLayerToMap()
Used for server-client coordinate compression and distance calculations.
- Decoding:
PolyUtil.decode(encodedPathString) - Distance:
SphericalUtil.computeDistanceBetween(latLng1, latLng2)
- Performance: For massive datasets (e.g., parsing huge GeoJSON files), do not block the main thread. Parse on a background dispatcher and only call
layer.addLayerToMap()on the UI thread. - Custom Renderers: If the user wants custom cluster icons, extend
DefaultClusterRendererand overrideonBeforeClusterItemRenderedandonBeforeClusterRendered.