How to Set Up Google APIs for Location Services: Distance Calculation, Geocoding, Journey Pricing, Address Suggestions and Map Display

How to Set Up Google APIs for Location Services: Distance Calculation, Geocoding, Journey Pricing, Address Suggestions and Map Display

This comprehensive guide will walk you through setting up the Google Maps Platform APIs to enable essential location features in your application including distance calculations, geocoding, journey pricing, address autocomplete, and interactive map displays.


Google Account Setup


1. Create or Choose Account

Register for a new Google developer account or use your existing one to access the Google Cloud Platform.

2. Create Project

Navigate to APIs & Services → Credentials in your Google Cloud Console. Create a new project (we recommend using your company name) or select an existing one. You'll find the option to create or select a project in the top navigation bar next to the Google Cloud logo.

3. Enable Required API Services

Go to APIs & Services → Library and enable the following services:

  • Directions API
  • Places API
  • Geocoding API
  • Maps JavaScript API
  • Maps Embed API



4. Setup Browser Key

a) Click Create credentials → API key → RESTRICT KEY

b) Enter "Browser key" in the API name field

c) Under Application restrictions, select HTTP referrers (websites)

d) In the Website restrictions section, click ADD AN ITEM, then enter the URL address which can be found in your Admin panel → Settings → Google → API keys → Browser key section. Add each URL in a new row.

f) In the API restrictions section, click Restrict Key and select the following APIs from the dropdown menu:

  • Maps JavaScript API
  • Maps Embed API
  • Directions API
  • Places API
  • Geocoding API

g) Copy the generated API key from the top-right corner

h) Save all changes

j) Return to your Dispatch Panel → Settings → Google → Google API Key restrictions configuration and paste the API key into both the Maps JavaScript API key and Maps Embed API key fields.



5. Setup Server Key

a) Go to Create credentials → API key → RESTRICT KEY

b) Enter "Server key" in the API name field

c) Under Application restrictions, select IP addresses (web servers, cron jobs, etc.)

d) In the Accept requests from these server IP addresses section, click ADD AN ITEM, then enter your Server IP which can be found in Admin panel → Settings → Google → API keys → Server key section. Add each IP address in a new row.

f) In the API restrictions section, click Restrict Key and select the following APIs from the dropdown menu:

  • Directions API
  • Places API
  • Geocoding API

g) Copy the generated API key from the top-right corner

h) Save all changes

j) Return to your Software → Settings → Google → Google API Key restrictions configuration and paste the API key into the Directions API, Places API and Geocoding API fields.



Note: If you encounter any issues, try temporarily disabling API key restrictions to check if the system works without them. If it does, this indicates that the restrictions weren't configured correctly.

6. Setup Billing

You must enable a billing profile for your project in the Billing → Overview tab. Without billing enabled, Google will apply strict daily usage limits and your API implementation won't function properly.

Note: You can find more information about usage limits and charges in the Google Maps Platform documentation.



7. Setup a Budget

Avoid unexpected charges by creating budgets to monitor all your Google Cloud Platform costs in one place. Configure budget alert rules to receive notifications when spending reaches certain thresholds. Detailed budget setup instructions are available in Google's documentation.

Note: This service is provided by Google, a third-party company. We don't take responsibility for any changes in how this service operates. Any issues with Google Maps Platform services must be addressed directly with Google.

8. Troubleshooting Common Error Messages

"You must use an API key to authenticate each request to Google Maps Platform APIs"

This indicates incomplete API setup. Review all the steps above to ensure you haven't missed anything.

"This page can't load Google Maps correctly"

Verify that your Google billing profile is enabled and that the Browser Key restrictions are configured correctly according to this guide.

"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 error occurs when Google API Server Key restrictions are enabled, but the specific IP address (X.X.X.X) shown in the error message isn't included in your allowed IP addresses list.

Your server might use multiple IP addresses to connect to Google API services. You'll need to add all of these IPs to your allowed list. To add missing IP addresses:

  1. Go to your Google API Console
  2. Edit your Server Key settings
  3. Under "Application restrictions → IP addresses → Accept requests from these server IP addresses" section, add the IP address displayed in the error message (X.X.X.X)


Implementing Google Maps APIs in Your Application

Once you've successfully set up your API keys and enabled billing, you can begin implementing the various Google Maps Platform features in your application:

  1. Distance Calculation using the Directions API
  2. Geocoding to convert addresses to coordinates and vice versa
  3. Journey Price Estimation based on distance and travel mode
  4. Address Suggestions using the Places Autocomplete feature
  5. Interactive Map Display with the Maps JavaScript or Embed APIs

Each implementation will require using your configured API keys for authentication with the respective Google services.