Google Maps Platform β APIs, Keys & Usage
Last reviewed: 2026-09-17
Purpose: Reference for the Google Maps Platform β the individual APIs, secure API-key provisioning and restriction, and minimal usage examples for the browser and REST endpoints.
Overview
Google Maps Platform is a family of location APIs billed per request against a Google Cloud project. Keys are project-scoped credentials: each key can be restricted to specific APIs and to specific callers (HTTP referrers, IP addresses, or mobile app identities), which is the primary defence against key theft and runaway billing.
A typical request flow:
Client (browser or server)
β HTTPS request signed with an API key
βΌ
Google Maps Platform endpoint βββΊ Geocoding / Directions / Places / JS API
β
ββββΊ usage recorded against the Cloud project β billing + quotas
Topics Covered
- Maps JavaScript API β embed interactive maps in web pages
- Geocoding API β convert addresses to coordinates and back
- Directions API β routes and travel times
- Places API β businesses, addresses and points of interest
- Distance Matrix API β travel time/distance for many origins and destinations
- Elevation API β ground elevation for coordinates
- Roads API β snap GPS traces to the road network
- API key provisioning, restriction and rotation
API Key Setup
- Go to the Google Cloud Console
- Create a new project (or select an existing one)
- Navigate to APIs & Services β Credentials
- Click Create Credentials β API Key
- Restrict the key (application restriction + API restriction β see the table below)
- Enable only the APIs the key needs:
- Maps JavaScript API
- Geocoding API
- Directions API
- Places API
- Distance Matrix API
- Reference the key from an environment variable or secret manager rather than source code
Restricting Keys
| Restriction | Applies to | Notes |
|---|---|---|
| HTTP referrers | Browser-side keys | Lock to your domains, e.g. https://example.com/* |
| IP addresses | Server-side calls | Lock to egress IPs or CIDR ranges |
| Android / iOS apps | Mobile SDKs | Lock to package name + signing certificate |
| API restrictions | All keys | Enable only the APIs that key must call |
| Quotas | Per API, per project | Set per-key daily quotas to cap spend |
Security note: never commit a key to a repository, never ship a server-side key to a browser, and prefer separate keys per environment (dev / staging / prod) so one can be revoked alone.
Usage Examples
Web β Maps JavaScript API
<script>
function initMap() {
const map = new google.maps.Map(document.getElementById("map"), {
center: { lat: 48.8566, lng: 2.3522 },
zoom: 12,
});
}
</script>
<script
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"
async defer>
</script>
Load the key through a server-side template or build-time placeholder, not as a literal committed to the repository.
Geocoding β REST
curl "https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY"
Directions β REST
curl "https://maps.googleapis.com/maps/api/directions/json?origin=Paris&destination=Lyon&mode=driving&key=YOUR_API_KEY"
Places β REST (nearby search)
curl "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=48.8566,2.3522&radius=1000&type=restaurant&key=YOUR_API_KEY"
Distance Matrix β REST
curl "https://maps.googleapis.com/maps/api/distancematrix/json?origins=Paris&destinations=Lyon|Marseille&key=YOUR_API_KEY"
All REST endpoints return JSON with a status field (OK, ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED, β¦) β check it before parsing the payload.
Cost & Quota Controls
| Control | Where | Why |
|---|---|---|
| Budget alerts | Cloud Billing | Warn before spend spikes |
| Per-API quotas | APIs & Services β Quotas | Hard ceiling per endpoint |
| Key-level quotas | Credentials β key | Contain the blast radius of one leaked key |
| Usage metrics | Cloud Monitoring | Attribute traffic to specific callers |
| Caching | Application side | Geocoding and elevation results rarely change β cache them |
Google Cloud grants a recurring monthly credit, but it is a billing credit, not a free tier: overage is charged normally.
Security Best Practices
- Restrict API keys β never leave a key unrestricted
- Use environment variables β never hardcode API keys in source code
- Enable billing alerts β set up budget alerts in Google Cloud Console
- Monitor usage β track API calls in the Cloud Console dashboard
- Rotate keys β periodically regenerate keys and retire the old ones
- Separate keys per environment β dev, staging and production keys independently revocable
Resources
- Google Maps Platform Documentation
- Google Cloud Console
- Maps JavaScript API Reference
- Geocoding API Guide
- Pricing
- Misc β Miscellaneous Technical Notes β API design and auth notes in this KB