Set up the Google API to calculate distance between locations, geocode locations, calculate the journey price, get address suggestions and display a map.
Google account setup
1. Create or choose account
Register or use your existing Google developer account.
2. Create project
In the account, go to APIs & Services -> Credentials and create a New project (we recommend using your company name).
3. Enable API Services
Go to APIs & Services -> Library and find and enable the services listed below.
- Directions API
- Places API
- Geocoding API
- Maps Embed API
a) go to Create credentials -> choose option API key -> click RESTRICT KEY
b) In API name field enter Browser key
c) In section Application restrictions -> select HTTP referrers (websites), then a new option appear Website restrictions
d) In section Website restrictions click ADD AN ITEM ,then in New Item enter two addresses http://example.com/* and https://example.com/* which can be found in Software -> Settings -> Google tab, just hover over or click title Google API Key restrictions configuration. Each URL should be entered in a new row.
f) In section API restrictions click Restrict Key and from drop-down menu select:
– Maps Embed API
– Directions API
– Places API
– Geocoding API
g) Copy API keys (available top-right side)
h) Save changes.
5. Setup Server key
a) Go to Create credentials -> choose option API key -> click RESTRICT KEY
b). In API name field enter Server key
c). In section Application restrictions -> select IP addresses (web servers, cron jobs, etc.), a new option appear Accept requests from these server IP addresses
d). In section Accept requests from these server IP addresses click ADD AN ITEM , in New Item enter Server IP which can be found in Software -> Settings -> Google tab -> click title Google API Key restrictions configuration and copy Server Key.
In software version 3.10.2 and below this Server IP is not display but domain or sub-domain IP address can be found here. Enter the name in the box and click “Lookup” button.
f). In section API restrictions click Restrict Key and from drop-down menu select
– Directions API
– Places API
– Geocoding API
g). Copy API keys (available at top right hand corner)
h). Save changes.
j). Now go back to Software -> Settings -> Google -> Google API Key restrictions configuration and past the API key into fields Directions API, Places API and Geocoding API.
Note: In case you have any problems please disable API key restriction to see if system works without it. If it does then it means the restriction hasn’t been set correctly.
6. Setup Billing
You have to enable billing profile for your project in Billing -> Overview tab otherwise Google will apply daily limits and the API you have created won’t work. Please see the last screenshot below for more details.
Note: You can read more about limits and charges here.
7. Setup a budget
Avoid surprises on your bill by creating budgets to monitor all your Google Cloud Platform charges in one place. Also stay informed of your expenses by setting up budget alert rules to trigger notifications. Read more about how to set a budget here.
Note: This service is provided by a third party company. We don’t take any responsibility for any changes in how this service operates. Any issue with this service will need to be discussed directly with the company which provides the service.
8. Error messages
Here are some potential error messages and how you can deal with them.
"You must use an API key to authenticate each request to Google Maps Platform APIs"
This means that the APIs has not been completed. Check if you completed all the above points and if something is missing.
"This page can't load Google Maps correctly"
Please make sure that Google billing profile is enabled in your Google account and the Browser Key restrictions are set up correctly as per above guide. Once this is done, please try again.
"This IP, site or mobile application is not authorized to use this API key. Request received from IP address X.X.X.X, with empty referer"
This might happen when Google API Server Key restrictions are enabled, but the IP address (X.X.X.X) displayed in the error message is not added to allowed IP addresses list.
Sometimes your server might be using few IP addresses to connect to Google API service in the background therefore you will need to list all of these IPs in your Google account.
To add missing IPs please go to your Google API Console and edit Server Key and then in “Application restrictions -> IP addresses (web servers, cron jobs, etc.) -> Accept requests from these server IP addresses” section add the IP address displayed in error message (X.X.X.X).