Add Map API key
πΊοΈ Adding Google Maps API Key to Your Flutter App
This guide explains how to generate and add a Google Maps API Key for both Android and iOS platforms in a Flutter project.
π Step 1: Enable Required APIs on Google Cloud Consoleβ
1οΈβ£ Go to the Google Cloud Platform.
2οΈβ£ Click on Console.
3οΈβ£ Select your Firebase Project (e.g., eDemand
).
4οΈβ£ In the search bar, type APIs & Services and open it.
5οΈβ£ Enable the following APIs one by one:
- Maps SDK for Android
- Maps SDK for iOS
- Places API (for autocomplete & location search)
- Geocoding API (for converting addresses to coordinates)
- Geolocation API
- Maps Embed API
β
π Step 2: Get API Keys for Android & iOSβ
1οΈβ£ Navigate to APIs & Services > Credentials.
2οΈβ£ Locate your API keys for Android and iOS.
3οΈβ£ Copy them for use in your project.
π€ Step 3: Setup API Key for Androidβ
1οΈβ£ Open your Flutter project in your code editor.
2οΈβ£ Navigate to: android/app/src/main/AndroidManifest.xml
3οΈβ£ Inside the <application>
tag (before <activity>
), add the following meta-data:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_ANDROID_API_KEY_HERE" />
Replace "YOUR_ANDROID_API_KEY_HERE" with your actual Google Maps API Key.
π Step 4: Setup API Key for iOSβ
1οΈβ£ Open the iOS folder in your Flutter project.
2οΈβ£ Open:
ios/Runner/AppDelegate.swift
3οΈβ£ In AppDelegate.swift
, ensure that GoogleMaps
is imported at the top of the file, but only if it's not already present
import GoogleMaps
4οΈβ£ Add the following line inside didFinishLaunchingWithOptions
:
GMSServices.provideAPIKey("YOUR_IOS_API_KEY_HERE")
Replace "YOUR_IOS_API_KEY_HERE" with your actual Google Maps API Key.
- If the map doesnβt load, check the Google Cloud Console to ensure that the APIs are enabled and the API key has no restrictions.
- In production, itβs recommended to restrict your API key to your appβs SHA-1 certificate (for Android) and Bundle ID (for iOS).
π Your Google Maps API Key is now set up and ready to use in your Flutter app! π