How to Get a Google Maps API Key: Retrieve Latitude and Longitude from Addresses in Google Sheets

Have you ever wanted to automatically retrieve latitude and longitude from addresses to enhance data analysis or improve workflow efficiency?

With the Google Maps API, this becomes possible.

However, to get started, you first need to obtain an API key.

In this article, we’ll walk you through the step-by-step process of obtaining your Google Maps API key.

TOC

About Google Maps API

The Google Maps API is a platform provided by Google that allows you to access various map-related features.

It supports a wide range of applications, including map display, route navigation, and retrieving location information.

To meet diverse mapping needs, Google offers specialized APIs tailored to specific purposes.

For example, the Google Maps API is commonly used in the following scenarios:

  • Geocoding API: Converts addresses to latitude and longitude, and vice versa.
  • Directions API: Provides route navigation and calculates travel distances.
  • Places API: Searches for nearby places and retrieves detailed information about them.

The Geocoding API specializes in retrieving latitude and longitude from addresses (known as “geocoding”).

In this guide, we’ll focus on obtaining the API key required to use the Geocoding API, one of the many features offered by the Google Maps API.

Steps to Obtain a Google Maps API Key

Obtaining a Google Maps API Key

The API key created through Google Cloud Platform (GCP) can be used not only for the Google Maps API but also for other Google Cloud-related APIs, such as the YouTube Data API and Google Drive API.

However, for better security and easier troubleshooting, it is recommended to manage API keys separately for each service or purpose.

In this guide, we will create an API key specifically for Google Maps API-related purposes and refer to it as the Google Maps API Key.

STEP
Creating a Google Cloud Platform (GCP) Account

Visit the official Google Cloud Platform (GCP) website.

If you’re using GCP for the first time, click on “Get Started for Free” and log in with your Google account or create a new one.

You’ll receive $300 in free credits to use for various GCP services, including the Google Maps API.

STEP
Selecting a Project

After logging in, click on “Select a Project” located in the top-left corner of the screen.

Create a new project here to begin setting up and preparing for API usage.

STEP
Creating a Project

Click on “New Project” to create a new project.

STEP
Naming Your Project

Choose a name for your project and click the “Create” button.

  • Example: My Maps Project
  • A default project name will be pre-filled, but you can change it to any name you like.
STEP
Selecting the Created Project

Go to “Select a Project” and choose the project you just created.

STEP
Selecting “APIs & Services”

After selecting your project, click on “APIs & Services” from the menu.

STEP
Accessing the Library

Next, click on “Library” under the APIs & Services section.

STEP
Searching for Geocoding API

Use the search bar to look for “Geocoding API”.

STEP
Enabling the API

From the search results, select “Geocoding API”.

Click the “Enable” button to activate the API.

STEP
Obtaining the API Key

Navigate to “APIs & Services” > “Credentials” from the menu.

Click “Create Credentials” and select “API Key”.

STEP
Copying the API Key

Copy the generated API key.

Save it securely for later use in Google Apps Script or other integrations.

Saving the API Key in Script Properties

To use the API key in Google Apps Script (GAS), store it in the script properties.

Why Use Script Properties?
Security:

By storing the API key in script properties, you avoid hardcoding it into the script, reducing the risk of exposure to third parties.

Ease of Maintenance:

If the API key needs to be updated, you can simply modify the property without editing the script itself.

Reusability:

The same API key can easily be reused across different functions or projects without duplicating code.

STEP
Open the Apps Script Editor.

Open your Google Sheets, go to the “Extensions” menu, and click on “Apps Script” to open the editor.

STEP
Open the Project Settings

In the Apps Script editor, select “Project Settings”.

STEP
Add Script Properties

Select “Add Script Properties”.

Enter the key name (e.g., “Maps_API_KEY”) and the API key.

Once entered, click “Save Script Properties”.

Free Tier for Google Maps API

The Google Maps API offers a free usage tier of $200 per month.

This allows many projects to operate without incurring any costs.

For more details, visit the Google Maps Platform.

Conclusion

You’ve now successfully obtained your Google Maps API key.

With this API key, you can not only retrieve latitude and longitude from addresses but also leverage other features of the Google Maps API.

In the next article, we’ll show you how to integrate this API key with Google Sheets to fetch latitude and longitude from addresses. Stay tuned!

Our company offers support for improving work efficiency through the use of Google Apps Script.
If you need assistance with Google Apps Script customization or error resolution, please feel free to contact us.
We are fully committed to supporting your business improvements.

Contact us here

Let's share this post !

Comments

To comment

TOC