How to Create Google Maps API Keys for Gravity Geolocation
Follow the steps below to create both the Browser and Server API keys required for your Google Maps integration. These API keys allow the plugin to load maps, geocode addresses, provide address autocomplete, calculate routes, and use other Google Maps Platform services.
Step-by-Step Guide to Google Maps API Keys
1. Go to the Google Cloud Console
- Visit the Google Cloud Console.
- Log in with your Google account.
2. Create a New Project or Select an Existing One
- In the top navigation bar, click the Project Selector.
- Select an existing project or click New Project to create a new one.
- Give your project a name and click Create.
3. Enable Billing for the Project
Google Maps Platform requires billing to be enabled on the Google Cloud project that owns your API keys. Billing must be enabled even if your usage stays within Google’s free monthly usage thresholds.
- Make sure the correct project is selected in the Google Cloud Console.
- Open Billing from the left menu.
- If the project is not linked to a billing account, click Link a billing account or Enable billing.
- Choose an existing billing account or create a new one.
- Add or confirm a valid payment method.
If billing is not enabled, Google Maps may show errors such as:
Google Maps JavaScript API error: BillingNotEnabledMapErrorGeocoding Service: You must enable Billing on the Google Cloud Project
Note: Google Maps Platform provides free monthly usage thresholds for many API services instead of the previous universal monthly credit.
4. Enable Google Maps API Services
- From the Dashboard, click APIs & Services > Library.
- Search for and enable the APIs required by the features you plan to use. Most installations will require at least the following services:
- Maps JavaScript API
- Geocoding API
- Address Validation API (only if using Address Validation Field)
- Places API (New)
- Routes API
- Maps Static API
- Geolocation API
- Click each API and then click Enable.
Current Stable Release: The current stable version of the plugin still relies on Google's legacy Places API and Directions API for some features.
Enable all of the APIs listed above. If you are using the current stable release, also enable the following legacy APIs:
- Places API (Legacy) - Enable Here
- Directions API (Legacy) - Enable Here
5. Create a Browser API Key
- Go to APIs & Services > Credentials.
- Click + Create Credentials > API Key.
- An API key will be generated. Copy this key for later use.
- Click Restrict Key to limit its usage:
- Application restrictions: Select HTTP referrers (websites).
- Add your website domain, for example:
https://example.com/*. - If needed, also add your non-www/www version and staging domain. Local development domains can be added as additional HTTP referrers if needed.
- Under API restrictions, restrict this key to the browser APIs used by your site, such as Maps JavaScript API and Places API (New) or Places API (Legacy), depending on the plugin features you use.
- Save your changes.
6. Create a Server API Key
- While still on the Credentials page, click + Create Credentials > API Key.
- Another API key will be generated. Copy this key as well.
- Click Restrict Key:
- Application restrictions: Select IP addresses.
- Add the public IP address(es) of your web server.
- Under API restrictions, restrict this key to server-side APIs used by the plugin, such as Geocoding API, Routes API, or Directions API (Legacy), depending on the plugin features you use.
- Save your changes.
Important: Do not use an IP-restricted server key for browser-loaded maps. The browser key should use HTTP referrer restrictions, and the server key should use IP address restrictions.
Summary
- Browser API Key: Use HTTP referrer restrictions.
- Server API Key: Use IP address restrictions.
- Never use the Server API Key in front-end JavaScript.
Final Note
Properly configured Google Maps API keys are required for the plugin’s geolocation features to work correctly. Make sure billing is enabled, the required APIs are active, and each API key is restricted for its intended use.
If you recently enabled billing or enabled a new API, wait a few minutes, clear any site/plugin cache, and reload the page.
If you encounter issues, first verify that billing is enabled, the required APIs are active, and your API key restrictions are configured correctly. If the problem persists, refer to Google’s documentation or contact support.
