How to Use Google Places Autocomplete API

How to Use Google Places Autocomplete API

Introduction

The Google Places Autocomplete API provides automatic address and place suggestions based on a text string. These APIs are commonly used in web and mobile applications during typing stages, enhancing the user experience. In this article, we will first examine the requirements needed to use these APIs. Then, we will show you how to use Google Places Autocomplete API through Postman, a popular API testing tool.

How to Use Google Places Autocomplete API

Requirements

Before starting, make sure you have met the following requirements:

  • A Gmail or Google Workspace account.
  • A valid physical or virtual credit/debit card.
  • An API key for the Google Places API, which can be created in the Google Developer Console.

To learn more about the mentioned requirements and follow a more detailed procedure, you can read our introductory article on How to Use Google Places API.

How to Use Google Places Autocomplete API in Postman

Postman is a well-known tool for testing and interacting with APIs. It can also be a very useful tool for understanding the behavior of APIs before integrating them into your projects. You can follow these steps to test and use the Google Places Autocomplete API in Postman:

  1. Download and install Postman: Go to the official Postman website (https://www.postman.com/downloads/) and download the application for your operating system. Install Postman following the provided instructions.
  2. Open Postman and create a new request: After launching Postman, create a new request by clicking the “+” button at the top of the user interface.
  3. Configure the API request: Select the “GET” method from the dropdown menu and enter the following URL to make a request to the Google Places Autocomplete API.
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=YOUR_INPUT&key=YOUR_API_KEY

Replace “YOUR_INPUT” with the text you want to use for the search and “YOUR_API_KEY” with the API key generated in the Google Developer Console.

How to Use Google Places Autocomplete API in Postman

Customizing Requests to Google Places Autocomplete API

Google Places Autocomplete API offers several options to customize API calls, allowing you to obtain more specific and relevant results based on your application’s needs. You can customize API calls by adding parameters to the request URL. Here are some common parameters to customize your calls:

  • types: Use this parameter to limit results to specific types of places, such as ‘geocode’ (addresses) or ‘establishment’ (business establishments). For example: &types=geocode.
  • language: Set the language of the search results by specifying the language code. For example, to get results in Italian, add &language=it.
  • location: Provide geographic coordinates (latitude and longitude) to prioritize results close to a specific location. For example: &location=41.902782,12.496366.
  • radius: Set a radius in meters around the location specified in the location parameter to limit results to that geographic area. For example: &radius=50000.
  • strictbounds: Add this parameter to limit results to the geographic area defined by the radius parameter. Use &strictbounds without value.
  • componentRestrictions: Limit results to a specific country by adding this parameter followed by the ISO 3166-1 Alpha-2 country code. For example, to limit results to Italy, use &components=country:it.

By combining these parameters, you can customize calls to the Google Places Autocomplete API to suit your application’s needs, improving user experience and data accuracy. To get a complete list of these parameters, you can refer to the official documentation page for the Google Places Autocomplete API.

Customizing Requests to Google Places Autocomplete API

Conclusion

The Google Places Autocomplete API can be easily tested and used with Postman, offering the possibility to explore and better understand the API’s features. Follow these steps to experiment with the APIs before implementing them in your application.

Correlated Resources

how to use Google Places API

How to use Google Places API

Introduction

The Google Places API is a service able to return information about locations, using HTTP requests. Locations are defined internally to this API as as establishments, geographic locations, or prominent points of interest. It is possible to use the Google Places API with the most important programming languages. Google offers already implemented client libraries for Java, Javascript, Python, Objective-C and Go. It is however possible to use the Google Places API on every programming language supporting HTTP requests. This guide explains how to use Google Places API, properly configuring your Google account and creating an API key for it. In particular, here you will find:

  • How to properly set up a Google Cloud project to use the API
  • How to create an API key for your Google account to use the API
  • How to use the Google Places API with standard HTTP requests for every programming language
how to use Google Places API

How to create an API key for Google Places API

Requirements to meet in order to be able to create a new API key to be used for Google Places API are the following:

  • A gmail or a Google Workspace account
  • A valid physical or virtual credit/debit card

A gmail or a Google Workspace account is needed in order to access your Google Developers Console, where you will be able to create a new API key. Google Places API will need your workspace project to be linked to a valid payment method to successfully process requests. Here are the detailed steps you are required to follow:

  • Access your Google Developer Console with your gmail or Google Workspace account
  • Create a new project, eventually linked to an organization in case you’ve been logging into a Google Workspace account
Step 1 - Creating a new Google Cloud Project
Enable "Places API" under the "Library" section

Enabling the Google Places API

Enable “Places API” under the “Library” section of the Google Developer Console. You will be required to create a new billing account or, eventually, to associate one, if already existing. You will be required to enter valid payment information, otherwise you won’t be able to correctly enable your API. Google won’t charge your payment method until you overcome the monthly $200 free threshold. You can get more information about API pricing at the Google Places Pricing page.

Creating an API key for Google Places

At this point, an API key should be automatically created. Copy down your API key and limit its usage to the “Places API”. If an API key isn’t created automatically, you will only have to go to the “Credentials” section of your Google Developer Console, then to create a new “API Key“. Whenever your API key is created, you should always apply restrictions to libraries able to use it.

Correlated Resources