3.7 KiB
3.7 KiB
Google Maps API Setup Guide
This guide will help you configure Google Maps API keys for the Plan B Logistics app across different platforms.
Prerequisites
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the following APIs:
- Maps SDK for Android
- Maps SDK for iOS
- Maps JavaScript API (for web)
Get Your API Key
- Go to Google Cloud Console - Credentials
- Click "Create Credentials" > "API Key"
- Copy the API key
- IMPORTANT: Restrict your API key by platform and add restrictions
Platform-Specific Configuration
Android
- Open
android/app/src/main/AndroidManifest.xml - Add the following inside the
<application>tag:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_ANDROID_API_KEY"/>
iOS
- Open
ios/Runner/AppDelegate.swift - Import GoogleMaps at the top:
import GoogleMaps
- Add the following in the
applicationmethod beforeGeneratedPluginRegistrant.register(with: self):
GMSServices.provideAPIKey("YOUR_IOS_API_KEY")
Web
- Open
web/index.html - Add the following script tag in the
<head>section:
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_WEB_API_KEY"></script>
macOS
- Open
macos/Runner/AppDelegate.swift - Import GoogleMaps at the top:
import GoogleMaps
- Add the following in the
applicationDidFinishLaunchingmethod:
GMSServices.provideAPIKey("YOUR_MACOS_API_KEY")
API Key Restrictions (Recommended)
For security, restrict your API keys by platform:
Android API Key
- Application restrictions: Android apps
- Add your package name:
com.goutezplanb.planb_logistic - Add SHA-1 certificate fingerprint
iOS API Key
- Application restrictions: iOS apps
- Add your bundle identifier:
com.goutezplanb.planb-logistic
Web API Key
- Application restrictions: HTTP referrers
- Add your domain:
https://yourdomain.com/*
macOS API Key
- Application restrictions: macOS apps (if available, otherwise use iOS restrictions)
Security Best Practices
- Never commit API keys to Git: Add them to
.gitignoreor use environment variables - Use different keys per platform: This helps track usage and limit damage if a key is compromised
- Set up billing alerts: Monitor API usage to avoid unexpected costs
- Enable only required APIs: Disable unused APIs to reduce attack surface
Environment Variables (Optional)
For better security, you can use environment variables or secret management:
- Create a
.envfile (add to.gitignore) - Store API keys there
- Use a package like
flutter_dotenvto load them at runtime
Testing
After configuration:
- Restart your Flutter app
- Navigate to a delivery route
- The map should load with markers showing delivery locations
- If you see a blank map or errors, check:
- API key is correctly configured
- Required APIs are enabled in Google Cloud Console
- No console errors in DevTools
Troubleshooting
Map shows but is gray
- Check if the API key is valid
- Verify billing is enabled on your Google Cloud project
"This page can't load Google Maps correctly"
- API key restrictions might be too strict
- Check the browser console for specific error messages
Markers don't appear
- Verify delivery addresses have valid latitude/longitude
- Check browser/app console for JavaScript errors
Cost Management
Google Maps offers a generous free tier:
- $200 free credit per month
- Approximately 28,000 map loads per month free
Monitor your usage at: Google Cloud Console - Billing