Get Started (original) (raw)
This page shows you how to get an API key, enable the required APIs, and load the Places Library, so that you can work with the Place class.
Get an API key and enable the required APIs
Before using the Place class, you need to:
- Create a Cloud project with a billing account.
- Get an API key.
- Enable the following APIs:
- Maps JavaScript API
- Places API
- Places API (New) (required to use Text Search (New) and Place Autocomplete)
To learn more, see Set up your Google Cloud project.
Load the Places Library
To load the Places Library, first load the Maps JavaScript API, by adding the inline bootstrap loader to your application code, as shown in the following snippet:
Next, use the await
operator to call importLibrary()
from within an async
function, as shown here:
const {Place} = await google.maps.importLibrary("places");
Your function can also load libraries without declaring a variable for the needed classes:
async function initMap() { google.maps.importLibrary("places"); ... }
initMap();
Alternatively, you can load the libraries directly in HTML as shown here:
For more information about loading libraries, seeLoad the Maps JavaScript API.