No modern web project or mobile app today gets far without integrating some kind of geolocation service. Among these, Google Maps Platform remains the leader, offering a powerful set of tools for rendering maps, routing, and place search.
To start working with these tools, you need an API key. In this guide, we’ll walk through, step by step, how to get one and configure it correctly for secure and efficient use, in line with Google’s current rules and requirements.
Step 1: Create a Google Cloud Platform (GCP) account
To use the Google Maps API you need an account on Google Cloud Platform (GCP). This is the unified platform that manages all Google services, maps included.
Setting up a billing account
This is the single most important step, and the one people most often skip. Google Maps Platform runs on a pay-as-you-go model. That said, Google provides a free monthly credit (around $200 at the time of writing), which is enough for most small and mid-sized projects.
- Why it’s mandatory: Even if you never exceed the free credit, your API key won’t activate without an active billing profile attached to it.
- What to do: Go to the Billing section in GCP and create a new billing account by adding your card.
Step 2: Create a new project and enable the APIs
Every API key is tied to a specific project in GCP.
Creating a project
- In the top menu of the GCP Console, choose “Select a project.”
- Click “New Project.”
- Name it after your app (for example, “My-Awesome-Map-App”).
Enabling the APIs you need
Google Maps Platform is made up of dozens of individual APIs. For your key to work, you have to enable the ones you plan to use. The most common ones:
- Maps JavaScript API: for rendering an interactive map on your site.
- Places API: for place search and address autocomplete.
- Geocoding API: for converting an address into coordinates (and back).
- Go to “APIs & Services” -> “Library.”
- Search for the API you need and click “Enable.”
Step 3: Generate and restrict your API key (best practice)
This step is critical for security. An unrestricted key can be picked up and abused by bad actors, which can lead to runaway charges on your billing account.
Generating the key
- Go to “APIs & Services” -> “Credentials.”
- Click “Create Credentials” and select “API key.”
- The system generates your unique key. Save it right away, and never make it public!
Setting API restrictions
Under Google’s current guidance, you should restrict how your key can be used.
Application restrictions
This stops your key from being used on third-party sites.
- For websites: choose “HTTP referrers” and enter your site’s domain:
*.yourdomain.com/*(for access from all subdomains)yourdomain.com/*(for access on the root domain)
- For mobile apps: choose “Android apps” or “iOS apps” and enter your app’s SHA-1 certificate fingerprint or Bundle ID, respectively.
API restrictions
This makes sure the key can only call the APIs you’ve explicitly enabled.
- Choose “Restrict key.”
- Check only the boxes for the APIs you actually plan to use (for example, Maps JavaScript API, Places API).
Step 4: Add the key to your project
Once you’ve generated and restricted the key, you can drop it into your code.
Example for a website (JavaScript API)
To load a map on a web page, use the following snippet, replacing YOUR_API_KEY with your own key:
HTML
<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"> </script>
Tips for working with Google Maps Platform
- Monitoring: Check the “Billing” and “APIs & Services” sections regularly to track usage and spend. You can set budgets and alerts to avoid surprise charges.
- Key rotation: For better security, periodically generate new API keys and remove the old ones.
- Server-side keys: If you call an API from your backend (for example, Geocoding for bulk processing), always use a separate key restricted by your server’s IP address rather than by HTTP referrer.
Getting a Google Maps Platform API key is the first and most important step toward building a solid geo-enabled feature. Follow this guide and you’ll keep your project both secure and stable.