Before you begin
Before you start using the Places SDK for Android, you need a project with a billing account and the Places SDK for Android enabled. To learn more, see Set up in Cloud console.
Creating API keys
The API key is a unique identifier that authenticates requests associated with your project for usage and billing purposes. You must have at least one API key associated with your project.
To create an API key:
Console
-
Go to the Google Maps Platform > Credentials page.
-
On the Credentials page, click Create credentials > API key.
The API key created dialog displays your newly created API key. -
Click Close.
The new API key is listed on the Credentials page under API keys.
(Remember to restrict the API key before using it in production.)
Cloud SDK
gcloud alpha services api-keys create \ --project "PROJECT" \ --display-name "DISPLAY_NAME"
Read more about the Google Cloud SDK , Cloud SDK installation , and the following commands:
Restricting API keys
Google strongly recommends that you restrict your API keys by limiting their usage to those only APIs needed for your application. Restricting API keys adds security to your application by protecting it from unwarranted requests. For more information, see API security best practices.
When you restrict your API key, you must provide the SHA-1 certificate fingerprint of the signing key that was used to sign the application. There are two certificate types:
- Debug certificate: Only use this certificate type with apps you're testing and other non-production code. Do not attempt to publish an app that's signed with a debug certificate. The Android SDK tools generate this certificate automatically when you run a debug build.
- Release certificate: Use this certificate when you're ready to release your app to an app store. The Android SDK tools generate this certificate when you run a release build.
For more information about Android application signing and certificates, see the Sign your app guide.
For instructions on how to find your signing certificate fingerprint, see the references below:
- If you're using Play App Signing, see Working with API Providers.
- If you manage your own signing key, see Self-signing your application or refer to the instructions for your build environment.
To restrict an API key:
Console
-
Go to the Google Maps Platform > Credentials page.
- Select the API key that you want to set a restriction on. The API key property page appears.
- Under Key restrictions, set the following restrictions:
- Application restrictions:
- Select Android apps.
- Click + Add package name and fingerprint.
- Enter your package name and SHA-1 certificate fingerprint. For example:
com.example.android.mapexample
BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:91:AF:A1:66:6E:44:5D:75
- API restrictions:
- Click Restrict key.
- Select either Places API or Places API (New) from Select APIs dropdown, but not both. If the Places API is not listed, you need to enable it.
- To finalize your changes, click Save.
Cloud SDK
Places SDK for Android (New)
List existing keys.
gcloud services api-keys list --project="PROJECT"
Clear existing restrictions on existing key.
gcloud alpha services api-keys update "projects/PROJECT/keys/KEY_ID" \ --clear-restrictions
Set new restrictions on existing key.
gcloud alpha services api-keys update "projects/PROJECT/keys/KEY_ID" \ --api-target="places.googleapis.com" --allowed-application="sha1_fingerprint=SHA1_FINGERPRINT,package_name=ANDROID_PACKAGE_NAME"
Read more about the Google Cloud SDK , Cloud SDK installation , and the following commands:
Places SDK for Android
List existing keys.
gcloud services api-keys list --project="PROJECT"
Clear existing restrictions on existing key.
gcloud alpha services api-keys update "projects/PROJECT/keys/KEY_ID" \ --clear-restrictions
Set new restrictions on existing key.
gcloud alpha services api-keys update "projects/PROJECT/keys/KEY_ID" \ --api-target="places-backend.googleapis.com" --allowed-application="sha1_fingerprint=SHA1_FINGERPRINT,package_name=ANDROID_PACKAGE_NAME"
Read more about the Google Cloud SDK , Cloud SDK installation , and the following commands:
What's next
Now that you have an API key, create and configure a project as described in Set Up an Android Studio Project.