To configure your app to use the Places SDK for Android, follow these steps. They are required for all apps using the Places SDK for Android.
Prior to using the Places SDK for Android, do the following:
- Follow the Get an API Key guide to get, add, and restrict an API key.
- Enable billing on each of your projects.
- Enable the Places API for each of your projects.
Step 1. Install the SDK
The Places SDK for Android library is available through Google's Maven repository. To add the SDK to your app, do the following:
-
In the
buildscript.repositories
section of your top-levelbuild.gradle
file, make sure Google's Maven repo is listed:buildscript { repositories { google() // ... } }
-
In the
dependencies
section of your app-levelbuild.gradle
file, add a dependency to the Places SDK for Android:dependencies { implementation 'com.google.android.libraries.places:places:2.0.0' }
Step 2. Initialize the Places API client
Initialize the Places SDK for Android, as shown in the following example
(note that you pass the API key when calling
Places.initialize()
):
// Initialize the SDK Places.initialize(getApplicationContext(), apiKey); // Create a new Places client instance PlacesClient placesClient = Places.createClient(this);
You are now ready to begin using the Places SDK for Android!