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.
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.4.0' }
Step 2: Get an API key
- Enable billing on your project.
- Enable the Places API for your project.
- Follow the Get an API Key guide to get, add, and restrict an API key.
Step 3. Initialize the Places API client
Initialize the Places SDK for Android within an activity or fragment as shown in the following example
(note that you pass the API key when calling
Places.initialize()
):
Java
// Initialize the SDK Places.initialize(getApplicationContext(), apiKey); // Create a new PlacesClient instance PlacesClient placesClient = Places.createClient(this);
Kotlin
// Initialize the SDK Places.initialize(applicationContext, apiKey) // Create a new PlacesClient instance val placesClient = Places.createClient(this)
You are now ready to begin using the Places SDK for Android!