Finding the right place with the Google Places API

How to use the Google Places API for address autocomplete, nearby search, and to retrieve place details.

Finding the right place with the Google Places API

In this tutorial series, I'll show you how to use the Google Places API for address autocomplete, nearby search and retrieving place details. I'll explain what each API does, cover pricing, and end each blog post with a hands-on example to help you quickly implement the Places API in your web app.

Autocomplete, Place Details, Place Photos, Nearby Search and Text Search APIs
Autocomplete, Place Details, Place Photos, Nearby Search and Text Search APIs

Part 1: Finding the right place with the Google Places API (this article)
Part 2: Google address autocomplete with the Places API
Part 3: Google Place Details API and Place Photos API
Part 4: Google Nearby Search API
Part 5: Google Places Text Search

What is the Google Places API?

The Google Places API is a collection of APIs that transforms Google Maps into a powerful search engine. While many view Google Maps simply as a mapping tool, it actually functions more like a modern address book. Each "place" in this address book is an entry that includes details such as a name, type, address, geographic coordinates, and a unique identifier known as the place_id. Some places may also feature user-submitted photos and reviews. Because Google Maps is so popular, users are encouraged to leave honest reviews, whether to praise good service or highlight poor experiences.

The Google Places API allows you to look up entries in the address book and use this information directly in your app.

Google Places API Categories

Here are the five most used APIs within the Google Places API family:

Place Autocomplete provides location-based suggestions as users type into a search input field. It’s commonly used for address fields in applications, allowing users to quickly select from suggested results rather than typing out the full address.

Using Place Autocomplete to provide location-based suggestions in a search input text field
Using Place Autocomplete to provide location-based suggestions in a search input text field

Place Details and Place Photos gives you access to a wide variety of data about a location, from basic information like its name and address to rich user-generated content such as reviews and photos. It’s especially useful when you need to offer users comprehensive details about a place beyond just its name and location.

Using Place Details and Place Photos to include user ratings and photos to a listing
Using Place Details and Place Photos to include user ratings and photos to a listing

Nearby Search (sometimes known as the Nearby Places API) lets you you search for places within a specified area. You can refine your search by providing keywords or specifying the type of place you are looking for, making this API perfect for building apps to helps users discover relevant places around them.

Using nearby search to find restaurants, bakeries and supermarkets near a given location
Using nearby search to find restaurants, bakeries and supermarkets near a given location

Text Search serves as a drop in replacement for the Google Maps search box, enabling users to search for places with free-form text, whether it's a specific place name, address, or type of location. Unlike Nearby Search, which focuses on proximity, Text Search leverages AI to interpret user queries. These can range from specific searches like a restaurant name or address to more general ones such as "Best brewery in Vancouver."

Using the Text Search API to search for places using free-form text

Google Places API key

To start using the Google Places API, the first thing you need to do is set it up it in your Google Cloud console. First, create a new project from the console dashboard at https://console.cloud.google.com/ and name it places-api-demo. Click [CREATE].

Creating a new GCP project to test the Google Places API
Creating a new GCP project to test the Google Places API

To enable the Google Places APIs, go to the APIs & Services page by selecting it on the left hand menu. Once there, choose [+ Enable APIs and Services] and search for the "Places API". Two options should show up - "Places API" and "Places API (New)". We'll need both.

Enabling the Places API and Places API (new) in our GCP project
Enabling the Places API and Places API (New) in our GCP project

Click on each option and enable the API by selecting [ENABLE].

Adding the Places API to our GCP project
Adding the Places API to our GCP project

Next, while still in the places-api-demo project, use the left hand navigation bar to head to the Credentials page. Click on the [+ Create Credentials] button and choose the [API Key] option. On the next page, use the drop down menu to make sure that Places API and Places API (New) are both enabled.

Verifying that both the Places API and Places API (New) have been added to our project
Verifying that both the Places API and Places API (New) have been added to our project

For added security, it's important to set up a website restriction for your Google Maps API key to prevent unauthorized access. You can do this by clicking the [Add] button under the API Restrictions section. Since the Places API key is often used on the frontend, it can be exposed by inspecting the source code in a browser. To protect it, you can restrict the key to specific domains. In the example above, I've added *.afi.dev/* as a restriction, ensuring that the key can only be used by websites under the afi.dev domain.

Click [Save] and your Google Places API key should be good to go. To use it, click the [Show Key] button on the Credentials page.

Google Places API pricing

The Google Places API follows a pay-as-you-go pricing model, similar to other Google Maps Platform services. Here's what the price sheet (in CPM, or cost per thousand requests) for the Places API looks like:

0 - 100k 100k - 500k 500k - 1M 1M - 5M 5M - 10M 10M - 20M 20M +
Autocomplete
/ Request
$2.83 $2.27 $1.70 $0.85 $0.25 $0.17 $0.17
Autocomplete
/ Session
$17.00 $13.60 $10.20 $5.10 $1.28 $1.00 $1.00
Place Details $17.00 $13.60 $10.20 $5.10 $1.28 $1.00 $1.00
Place Photo $7.00 $5.60 $4.20 $2.10 $0.53 $0.16 $0.06
Nearby Search $32.00 $25.60 $19.20 $9.60 $2.40 $1.90 $1.90
Text Search $32.00 $25.60 $19.20 $9.60 $2.40 $1.90 $1.90

* CPM: cost per thousand requests

The first two tiers (0 - 100k and 100k - 500k) are available to the public. You just need to set up a GCP billing account with your credit card and every month and you'll be charged automatically based on volume. The higher tiers (500k and up) are only available if you work with a Google Maps Partner.

Typical use cases for the Google Places API

The Google Places API is widely used across various industries. Ride sharing companies leverage Place Autocomplete to help customers accurately enter pickup and drop-off locations. Meanwhile, real estate companies often use Nearby Search to display amenities within walking distance of a specific property listing, enhancing the user experience.

The Places API is also popular with the travel industry, which uses the Place Details and Place Photo APIs to add contact information, opening hours, user reviews, photos, and ratings to tourist attractions, hotels and restaurants. This allows travelers to make informed decisions about where to visit, stay, or eat during their trip.

One new and increasingly common way that the travel industry is using the Google Places API is by combining it with a Large Language Model, or LLM. For example, you can give ChatGPT-4o the following prompt:

"I'm interested in museums, cultural landmarks, nice neighborhoods and French restaurants. Plan a three day itinerary in France for me, starting at my hotel, Le Meurice, that takes my preferences into account. Provide your answer in JSON format and for each place, include the Google Maps place_id in your response."

And it will generate an itinerary that includes place_ids for each location suggested by the engine.

Using ChatGPT to generate place_ids in the response
Using ChatGPT to generate place_ids in the response

The response from the LLM and included place_ids can then be used by a trip planning app to provide personalized recommendations, together with reviews, photos, and ratings for tourist attractions and major landmarks.

Integrating the output of an LLM with the Google Places API
Integrating the output of an LLM with the Google Places API

What you'll learn in this tutorial series

By the end of this tutorial, you'll be an expert at Google Places API. Specifically, you will:

  • Gain hands-on experience setting up Place Autocomplete for address and location suggestions.
  • Understand how to use Place Details and Place Photos to fetch information about places, including address, phone number, opening hours, user ratings, and photos.
  • Learn how Nearby Search can help find nearby places such as restaurants, hotels, and attractions based on the user’s location.
  • Use the Text Search API to search for places by name, address, or type using a free-form text input.

👋 As always, if you have any questions or suggestions for me, please reach out or say hello on LinkedIn.

Next: Google address autocomplete with the Places API