Set up the Places SDK for Android

  • To use the Places SDK for Android, you'll need a project with billing enabled and the Places SDK enabled, which can be set up through the Cloud Console.

  • An API key, a unique identifier for authentication and billing, is required and can be created through the Cloud Console or the Cloud SDK.

  • For security, Google strongly recommends restricting your API keys by limiting their usage to necessary APIs and applying application restrictions with package names and SHA-1 certificate fingerprints.

  • Before using the API key, configure a project as detailed in the 'Set Up an Android Studio Project' documentation after obtaining the key.

This document describes the steps needed to start using the Places SDK for Android.

Prerequisites

This procedure guides you through setting up a Google Cloud Account and Google Cloud project with billing enabled. You should also be familiar with how you are charged for using the Places SDK for Android.

  1. Review billing and cost for usage at Places SDK for Android Usage and Billing.
  2. Verify that you have a Google Cloud Account.

    Sign in to the Google Cloud console
  3. Verify that you have a Google Cloud project with billing enabled.

    Go to the Billing page
    1. Select your project to open the Billing page.
    2. On the Billing page:

      • If billing is already enabled for the selected project, and you only have a single billing account, then the Billing page opens.
      • If you have multiple billing accounts, select Go to linked billing account to see the details about the billing account associated with the project.
      • If a billing account exists but is not associated with the project, you are prompted to link a billing account with the project.
      • If no billing account exists, or you want to create a new billing a account, select Manage Billing Accounts to create a new billing account. For more information, see Create a new self-serve Cloud Billing account.

Enable the SDK

Before you can use Places SDK for Android, you must use the Google Cloud console or the gcloud command to enable it in your Google Cloud project.

Places SDK for Android depends upon Places API (New). To enable Places API (New):

Console

  1. Open the product page in the Google Cloud console:

    Enable the Places API (New)
  2. Click the Enable button.

gcloud

gcloud services enable \
    --project "PROJECT" \
    "places.googleapis.com"

Read more about the Google Cloud SDK, Cloud SDK installation, and the following commands:

Configure API key

Google Maps Platform products are secured from unauthorized use by requiring API calls to include an API key.

Get an API key for use with Places API (New)

An API key is a unique alphanumeric string that associates your Cloud Billing account and Google Cloud project with the request your application makes to a Google Maps Platform API or SDK. To create a new key or add an API or SDK to an existing key, follow these instructions.

Console

  1. Go to the Google Maps Platform > Keys & Credentials page.

    Go to the Keys & Credentials page

  2. If prompted, select your project.
  3. Do one of the following:

    • Create a new key:

      1. Click Create credentials > API key.
      2. In the Create API key panel, open the Select API restrictions list.
      3. Clear any APIs that this key doesn't need, and make sure Places API (New) stays selected.
      4. Click Create. The panel displays your new API key.
    • Use an existing key:

      1. Click the name of the key.
      2. In the Select API restrictions list, select Places API (New).
      3. Click Save.

    Selecting an API here doesn't enable it. Make sure Places API (New) is enabled on its API Library page.

  4. To see the key string later, go to the Keys & Credentials page and click Show key for the key.

If the console looks different from these steps, see Create an API key and Add API restrictions in the Google Cloud documentation.

gcloud

Replace PROJECT_ID with your project ID in the following commands.

  • Create a new key: Run the following command, and replace DISPLAY_NAME with a name for the key.

    gcloud services api-keys create \
        --project="PROJECT_ID" \
        --display-name="DISPLAY_NAME" \
        --api-target=service=places.googleapis.com

    Read more about the Google Cloud SDK, Cloud SDK installation, and the following commands:

  • Use an existing key: Run the following command, and replace KEY_ID with the ID of the key. The --append flag keeps the APIs that the key already allows. Without it, the command replaces them.

    gcloud services api-keys update KEY_ID \
        --project="PROJECT_ID" \
        --append \
        --api-target=service=places.googleapis.com

    Read more about the Google Cloud SDK, Cloud SDK installation, and the following commands:

    The key ID isn't the key string or display name. To find it, run gcloud services api-keys list --project="PROJECT_ID". The ID is the last part of the name field: projects/PROJECT_NUMBER/locations/global/keys/KEY_ID.

To see the key string, run gcloud services api-keys get-key-string KEY_ID --project="PROJECT_ID".

Apply API key restrictions

Google strongly recommends that you restrict your API keys by limiting their usage to only the APIs and apps that need them. Restricting API keys adds security to your application by protecting it from unwarranted requests. API keys support two types of restrictions:

  • API restrictions specify which SDKs and APIs can be called using the API key. The console and the gcloud CLI require at least one API restriction when you create a key.
  • Application restrictions specify which websites, IP addresses, or apps can use an API key.

For more information about applying restrictions, see Restrict your API keys.

What's next

Now that you have enabled Places SDK for Android and configured an API key, see Set up an Android Studio project to learn more how to configure Xcode and how to pass the API key to your app.