|
| 1 | +--- |
| 2 | +name: maps-utils-android |
| 3 | +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. |
| 4 | +--- |
| 5 | + |
| 6 | +# Google Maps Utility Library for Android Integration |
| 7 | + |
| 8 | +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. |
| 9 | + |
| 10 | +## 1. Setup Dependencies |
| 11 | + |
| 12 | +Add the necessary dependency to the app-level `build.gradle.kts` file: |
| 13 | + |
| 14 | +```kotlin |
| 15 | +dependencies { |
| 16 | + // Google Maps Utility Library |
| 17 | + implementation("com.google.maps.android:android-maps-utils:3.9.0") // Check for the latest version |
| 18 | +} |
| 19 | +``` |
| 20 | +*(Note: If the user is using Jetpack Compose, they should ideally be using `maps-compose-utils` from the `android-maps-compose` repository instead of this library directly, though this library is the underlying foundation).* |
| 21 | + |
| 22 | +## 2. Core Features & Usage Patterns |
| 23 | + |
| 24 | +When a user asks for advanced features, implement them using these established patterns from the Utility Library: |
| 25 | + |
| 26 | +### Marker Clustering |
| 27 | +Used to manage multiple markers at different zoom levels. |
| 28 | +1. Create a `ClusterItem` data class. |
| 29 | +2. Initialize a `ClusterManager` inside `onMapReady`. |
| 30 | +3. Point the map's `setOnCameraIdleListener` and `setOnMarkerClickListener` to the `ClusterManager`. |
| 31 | +4. Add items using `clusterManager.addItem()`. |
| 32 | + |
| 33 | +### Heatmaps |
| 34 | +Used to represent the density of data points. |
| 35 | +1. Provide a `Collection<LatLng>` or `Collection<WeightedLatLng>`. |
| 36 | +2. Create a `HeatmapTileProvider` with the builder `HeatmapTileProvider.Builder().data(list).build()`. |
| 37 | +3. Add the overlay to the map: `map.addTileOverlay(TileOverlayOptions().tileProvider(provider))`. |
| 38 | + |
| 39 | +### GeoJSON and KML |
| 40 | +Used to import geographic data from external files. |
| 41 | +* **GeoJSON:** `val layer = GeoJsonLayer(map, R.raw.geojson_file, context); layer.addLayerToMap()` |
| 42 | +* **KML:** `val layer = KmlLayer(map, R.raw.kml_file, context); layer.addLayerToMap()` |
| 43 | + |
| 44 | +### Polyline Decoding and Spherical Geometry |
| 45 | +Used for server-client coordinate compression and distance calculations. |
| 46 | +* **Decoding:** `PolyUtil.decode(encodedPathString)` |
| 47 | +* **Distance:** `SphericalUtil.computeDistanceBetween(latLng1, latLng2)` |
| 48 | + |
| 49 | +## 3. Best Practices |
| 50 | +1. **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. |
| 51 | +2. **Custom Renderers:** If the user wants custom cluster icons, extend `DefaultClusterRenderer` and override `onBeforeClusterItemRendered` and `onBeforeClusterRendered`. |
0 commit comments