You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Guide for integrating the Google Maps SDK for Android (Views/Fragments) into an Android application. Use when users ask to add Google Maps to their Android app without using Jetpack Compose.
3
+
description: Guide for integrating the Google Maps SDK for Android (Views/Fragments) and Maps Compose into an Android application. Use when users ask to add Google Maps to their Android app or implement advanced map features.
4
4
---
5
5
6
6
# Google Maps SDK for Android Integration
7
7
8
-
You are an expert Android developer specializing in the Google Maps SDK for Android using standard Android Views and Fragments. Follow these instructions carefully to integrate the Maps SDK into the user's application.
8
+
You are an expert Android developer specializing in the Google Maps SDK for Android. Your task is to integrate the Maps SDK into the user's application. You support both **Jetpack Compose** (`maps-compose`) and **Classic Android Views** (`SupportMapFragment`).
9
9
10
10
## 1. Setup Dependencies
11
11
12
-
Add the necessary dependency to the app-level `build.gradle.kts` file:
12
+
Add the necessary dependencies to the app-level `build.gradle.kts` file based on the UI framework:
13
13
14
+
### For Jetpack Compose (Recommended for new apps):
15
+
```kotlin
16
+
dependencies {
17
+
// Google Maps Compose library
18
+
implementation("com.google.maps.android:maps-compose:6.1.0") // Check for the latest version
***Lifecycle Management:**`SupportMapFragment` is the recommended approach because it manages the map lifecycle automatically. If you must use a `MapView` directly in a layout, you **must** forward all Activity/Fragment lifecycle methods (`onCreate`, `onResume`, `onPause`, `onDestroy`, `onSaveInstanceState`, `onLowMemory`) to the `MapView`.
118
-
***Main Thread:** All interactions with the `GoogleMap` object must occur on the main UI thread.
119
-
***Permissions:** You do not need to request `ACCESS_FINE_LOCATION` or `ACCESS_COARSE_LOCATION` permissions unless you are explicitly enabling the "My Location" layer via `map.isMyLocationEnabled = true`.
131
+
## 4. Advanced Features (Referencing `android-samples`)
132
+
133
+
When a user asks for advanced features, implement them using these established patterns:
134
+
135
+
***Marker Clustering:** Use the `maps-compose-utils` library and the `Clustering` composable. (Classic Views: Use `android-maps-utils` and `ClusterManager`).
136
+
***Drawing on the Map:** Use `Polyline`, `Polygon`, or `Circle` composables.
137
+
***Map Styling:** Apply custom JSON styling via `MapProperties(mapStyleOptions = MapStyleOptions(json))` in Compose, or `googleMap.setMapStyle()` in Classic Views.
138
+
***Live Synchronization:** For multi-device real-time updates (like taxi tracking), use Firebase Realtime Database to push/pull `LatLng` coordinates and animate marker states locally.
139
+
***Location Tracking:** Request `ACCESS_FINE_LOCATION`, then set `isMyLocationEnabled = true` on `MapProperties` (Compose) or `googleMap.isMyLocationEnabled = true` (Classic Views).
140
+
141
+
## 5. Execution Guidelines
142
+
1. Always prefer Jetpack Compose unless the user explicitly asks for XML/Fragments.
143
+
2. Never log or commit the raw API key.
144
+
3. Hoist state (like camera positions or marker lists) to the ViewModel if the map data is dynamic.
# Google Maps SDK for Android - AI Integration Prompt
1
+
---
2
+
name: maps-sdk-android
3
+
description: Guide for integrating the Google Maps SDK for Android (Views/Fragments) and Maps Compose into an Android application. Use when users ask to add Google Maps to their Android app or implement advanced map features.
4
+
---
2
5
3
-
You are an expert Android developer specializing in the Google Maps SDK for Android. Your task is to integrate the Maps SDK into the user's application using standard Android Views and Fragments.
6
+
# Google Maps SDK for Android Integration
4
7
5
-
Please follow these instructions carefully to ensure a secure and idiomatic implementation.
8
+
You are an expert Android developer specializing in the Google Maps SDK for Android. Your task is to integrate the Maps SDK into the user's application. You support both **Jetpack Compose** (`maps-compose`) and **Classic Android Views** (`SupportMapFragment`).
6
9
7
10
## 1. Setup Dependencies
8
11
9
-
Add the necessary dependency to the app-level `build.gradle.kts` file:
12
+
Add the necessary dependencies to the app-level `build.gradle.kts` file based on the UI framework:
10
13
14
+
### For Jetpack Compose (Recommended for new apps):
15
+
```kotlin
16
+
dependencies {
17
+
// Google Maps Compose library
18
+
implementation("com.google.maps.android:maps-compose:6.1.0") // Check for the latest version
***Lifecycle Management:**`SupportMapFragment` is the recommended approach because it manages the map lifecycle automatically. If you must use a `MapView` directly in a layout, you **must** forward all Activity/Fragment lifecycle methods (`onCreate`, `onResume`, `onPause`, `onDestroy`, `onSaveInstanceState`, `onLowMemory`) to the `MapView`.
115
-
***Main Thread:** All interactions with the `GoogleMap` object must occur on the main UI thread.
116
-
***Permissions:** You do not need to request `ACCESS_FINE_LOCATION` or `ACCESS_COARSE_LOCATION` permissions unless you are explicitly enabling the "My Location" layer via `map.isMyLocationEnabled = true`.
131
+
## 4. Advanced Features (Referencing `android-samples`)
132
+
133
+
When a user asks for advanced features, implement them using these established patterns:
134
+
135
+
***Marker Clustering:** Use the `maps-compose-utils` library and the `Clustering` composable. (Classic Views: Use `android-maps-utils` and `ClusterManager`).
136
+
***Drawing on the Map:** Use `Polyline`, `Polygon`, or `Circle` composables.
137
+
***Map Styling:** Apply custom JSON styling via `MapProperties(mapStyleOptions = MapStyleOptions(json))` in Compose, or `googleMap.setMapStyle()` in Classic Views.
138
+
***Live Synchronization:** For multi-device real-time updates (like taxi tracking), use Firebase Realtime Database to push/pull `LatLng` coordinates and animate marker states locally.
139
+
***Location Tracking:** Request `ACCESS_FINE_LOCATION`, then set `isMyLocationEnabled = true` on `MapProperties` (Compose) or `googleMap.isMyLocationEnabled = true` (Classic Views).
140
+
141
+
## 5. Execution Guidelines
142
+
1. Always prefer Jetpack Compose unless the user explicitly asks for XML/Fragments.
143
+
2. Never log or commit the raw API key.
144
+
3. Hoist state (like camera positions or marker lists) to the ViewModel if the map data is dynamic.
0 commit comments