Adding maps to your app without a surprise bill: API key practices
Plan Google Maps key restrictions, usage monitoring and rotation while distinguishing visible client keys from secret server credentials.
Delivery, ride and booking apps all need maps. Google Maps Platform APIs require an API key or, where supported, OAuth 2.0. Google's security guidance (https://developers.google.com/maps/api-security-best-practices) is blunt about the financial side: you are financially responsible for charges caused by abuse of unrestricted API keys. This article turns that guidance into a checklist. It covers Google Maps Platform only; other map providers have their own rules.
The practices Google lists
For all key uses:
- Restrict your API keys to specific apps and specific APIs.
- Use separate keys for each app, so one leaked key affects less and usage quotas are easier to manage.
- Delete unused keys.
- Check your key usage regularly.
- Be careful when rotating keys.
- Split client-side and server-side usage into separate projects.
- Disable services you do not use.
For client-side apps: use the client-side SDKs and secure client-side web service calls. For server-side apps: protect web service keys, and use OAuth for server-to-server traffic.
Protect server-side credentials and never embed service-account keys in an untrusted client. Client-side Maps SDK/API keys can be visible by design: apply the correct application and API restrictions instead of pretending they can be kept secret in a shipped app. Google also describes App Check for supported integrations; check applicability before depending on it.
Rotating a key already in production
Google's advice: check usage before changing a key, since adding restrictions to a live key can break traffic you did not know about. After changing it, update all your apps. If the key has not been compromised, you can migrate apps to multiple new keys at your own pace and keep the original untouched until you see only one type of traffic, then restrict it. Regenerate only as a last resort, because it can cause disruption.
A launch checklist (our format)
| Item | Done? |
|---|---|
| One key per app (Android, iOS, web, server) | |
| Each key restricted to its app and the APIs it needs | |
| Keys kept out of the public code repository | |
| Unused APIs disabled | |
| Usage and billing alerts set, with quotas and incident response planned; an alert is not a hard spending cap | |
| Owner named for key rotation |
Questions for your developer
- Is any key visible in the app bundle or page source without restriction?
- If a key leaked tonight, who would notice and how?
- Are test and production keys separate?
- Do we use a maps feature that bills per request in a loop, such as repeated geocoding?
Limits
This article does not give prices. Check current Google Maps Platform pricing and quotas before designing features that call the APIs often.
By Omnistu.