How to Create Google Maps API Keys for Gravity Geolocation
Before You Begin
Gravity Geolocation requires two Google Maps Platform API keys: a Browser API Key for features that run in the visitor’s browser and a Server API Key for secure requests made by your WordPress site.
Create separate keys because each one needs different application restrictions. A browser key is visible in front-end page source by design, so it must be restricted to your websites. The server key should remain private and be restricted to the outbound public IP address or addresses used by your web server.
Create a Project and Enable Billing
Enable the Required Google Maps APIs
- In the Google Cloud Console, go to APIs & Services > Library.
- Search for each API your site needs.
- Open the API and click Enable.
Enable these APIs for Gravity Geolocation’s core map and location features:
- Maps JavaScript API: Displays and controls interactive maps.
- Places API (New): Powers current place and address autocomplete functionality.
- Geocoding API: Converts addresses to coordinates and coordinates to addresses.
Enable these APIs when you use the related feature:
- Routes API: Required for directions, distance, duration, and route-matrix calculations.
- Address Validation API: Required when a form uses the Address Validation Field.
- Maps Static API: Required when displaying static maps in entries, notifications, confirmations, or merge-tag output.
Do not enable Google’s Geolocation API for Gravity Geolocation. The plugin uses the visitor’s browser geolocation or the IP provider configured in the plugin settings for current-location detection.
Gravity Geolocation 3.5 API Requirements
Gravity Geolocation 3.5 uses Places API (New) for address autocomplete and Routes API for directions, distance, duration, and route-based travel calculations.
Version 3.5.1 includes temporary compatibility fallbacks for existing Address Autocomplete and Directions fields when a request fails because Places API (New) or Routes API is unavailable or blocked. The fallbacks do not cover every 3.5 feature and are not a substitute for enabling the current APIs.
For complete Gravity Geolocation 3.5 functionality:
- Enable Places API (New) in the Google Cloud project connected to Gravity Geolocation.
- Enable Routes API when using directions, distance, duration, or nearest-location travel calculations.
- Review the API restrictions on your Browser and Server API keys and allow the services used by each key.
- Confirm that both API keys are saved in the Gravity Geolocation settings.
If you upgraded from Gravity Geolocation 3.2.x and address suggestions or route calculations are not working, complete the steps above, wait several minutes for Google to apply the changes, clear any site or optimization cache, and test the form again.
If your existing Google Cloud project already has the legacy Places API or Directions API enabled, keep those services enabled temporarily while you transition. Gravity Geolocation 3.5.1 can use them only as compatibility fallbacks for existing Address Autocomplete and Directions fields. New Google Cloud projects may not offer legacy services, and other 3.5 features still require their documented current APIs.
Create the Browser API Key
Create the Server API Key
Important: Never place the Server API Key in front-end JavaScript or use an IP-restricted server key as the Browser API Key.
Add the Keys to Gravity Geolocation
- Sign in to your WordPress dashboard.
- Go to Forms > Settings > Gravity Geolocation.
- Paste the website-restricted key into Browser API Key (Required).
- Paste the private server key into Server API Key (Required).
- Click Save Settings.
Troubleshooting
- Places API (New) permission errors: Confirm that Places API (New) is enabled in the same project as the Browser API Key and is permitted by that key’s API restrictions.
- Routes API permission errors: Confirm that Routes API is enabled in the same project and permitted by the API key making the request.
- Legacy fallback does not activate: The 3.5.1 fallbacks apply only to existing Address Autocomplete and Directions fields when the corresponding new API is unavailable or blocked. Confirm that the legacy Places API or Directions API remains enabled and permitted on the Browser API Key.
- Billing errors: Confirm that the selected Google Cloud project is linked to an active billing account.
- API not activated: Confirm that the error names an API enabled in the same project as the key.
- Referer errors: Check the Browser API Key’s website restrictions and include the exact protocol and domain used by the page.
- Server restriction errors: Confirm the public outbound IP address seen by Google, not only the IP displayed for your domain.
- Recent changes: Wait a few minutes for new APIs or restrictions to take effect, clear site caches, and reload the page.
