Setup

This page describes what you need to do to get set up to start building with the Maps 3D SDK for Android. The setup process involves configuring a Google Cloud project and API for use with the SDK, and then setting up an Android Studio project. Complete these steps before adding your first 3D map to your app.

Set up a Google Cloud project and API key

Before you can start building with the Maps 3D SDK for Android, you need to set up a Google Cloud project and API key to use with the Maps 3D SDK for Android by completing the following steps:

Step 1

Console

  1. In the Google Cloud console, on the project selector page, click Create Project to begin creating a new Cloud project.

    Go to the project selector page

  2. Make sure that billing is enabled for your Cloud project. Confirm that billing is enabled for your project.

    Google Cloud offers a $0.00 charge trial. The trial expires at either end of 90 days or after the account has accrued $300 worth of charges, whichever comes first. Cancel anytime. For more information, see Billing account credits and Billing.

Cloud SDK

gcloud projects create "PROJECT"

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

Step 2

To use Google Maps Platform, you must enable the APIs or SDKs you plan to use with your project.

Note that some integrations require you to enable multiple APIs/SDKs. If you are not sure which APIs or SDKs to enable, try using the API Picker, or consult the documentation for the API/SDK you want to use.

To enable one or more APIs or SDKs:

Console

  1. See the Google Maps Platform APIs and SDKs that you can enable by going to the Maps API Library page in the Cloud console:

    Go to the Maps API Library page

  2. Click the API or SDK you want to enable.
    • If the button says ENABLE, click the button to enable the API or SDK.
    • If the button says MANAGE, the API or SDK is already enabled and you don't need to do anything further.
    • Clicking either button will display the dashboard for the API or SDK. (Click the DISABLE button to remove the API or SDK from this project.)

Cloud SDK

The following command enables all of the Maps, Routes, and Places APIs:

gcloud services enable \
    --project "PROJECT" \
    "addressvalidation.googleapis.com" \
    "areainsights.googleapis.com" \
    "tile.googleapis.com" \
    "aerialview.googleapis.com" \
    "elevation-backend.googleapis.com" \
    "routes.googleapis.com" \
    "geocoding-backend.googleapis.com" \
    "geolocation.googleapis.com" \
    "maps-android-backend.googleapis.com" \
    "maps-backend.googleapis.com" \
    "maps-embed-backend.googleapis.com" \
    "maps-ios-backend.googleapis.com" \
    "mapsplatformdatasets.googleapis.com" \
    "places-backend.googleapis.com" \
    "roads.googleapis.com" \
    "routeoptimization.googleapis.com" \
    "static-maps-backend.googleapis.com" \
    "street-view-image-backend.googleapis.com" \
    "timezone-backend.googleapis.com"

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

Use this command to enable the Environment APIs:

gcloud services enable \
    --project "PROJECT" \
    "airquality.googleapis.com" \
    "solar.googleapis.com" \
    "pollen.googleapis.com"

Step 3

This step only goes through the API Key creation process. If you use your API Key in production, we strongly recommend that you restrict your API key. You can find more information in the product-specific Using API Keys page.

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

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

    Go to the Credentials page

  2. On the Credentials page, click Create credentials > API key.
    The API key created dialog displays your newly created API key.
  3. 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 services api-keys create \
    --project "PROJECT" \
    --display-name "DISPLAY_NAME"

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

To enable the SDK, see the Maps 3D SDK for Android page in the Google Cloud console. For more information about completing these steps, see Getting started with the Google Maps Platform.

Set up an Android Studio project

This section explains how to create and configure an Android Studio project for use with the Maps 3D SDK for Android.

Part 1: Set up your project and Gradle configuration

  1. Create a new Android Studio project using the Empty Views Activity template.

  2. If you are using Git for source control, modify the project .gitignore file to prevent your secrets file from being committed to version control:

    • In your project's root directory, open the .gitignore file.
    • Add the following line:
    secrets.properties
    
  3. Update the project-level build.gradle.kts file:

    • In your project's root directory, open the build.gradle.kts file.
    • In the plugins block, add the Secrets Gradle plugin:
    plugins {
      alias(libs.plugins.android.application) apply false
      alias(libs.plugins.kotlin.android) apply false
      alias(libs.plugins.secrets.gradle.plugin) apply false // Add this line
    }
    
  4. Update the gradle/libs.versions.toml file: - Open the gradle/libs.versions.toml file, which is usually located in the gradle directory within the project root directory. - In the versions section, add the versions for the SDK and Secrets Gradle plugin:

    maps3dSdk = "0.0.1" # Update this value to match the SDK version to include
    secretsGradlePlugin = "2.0.1"
    
    -   In the library section, add the SDK library:
    
    play-services-maps3d = { module = "com.google.android.gms:play-services-maps3d", version.ref = "maps3dSdk" }
    
    -   In the plugin section, add the Secrets Gradle plugin:
    
    secrets-gradle-plugin = { id = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", version.ref = "secretsGradlePlugin" }
    
  5. Update the module-level app/build.gradle.kts file: - Open the module-level build.gradle.kts file, which is usually located within the app directory. - At the top of the file, add the Secrets Gradle plugin to the plugins block:

    plugins {
      alias(libs.plugins.android.application)
      alias(libs.plugins.kotlin.android)
      alias(libs.plugins.secrets.gradle.plugin) // Add this line
    }
    
    -   In the `dependencies` block, add the SDK:
    
    dependencies {
      // ... other dependencies
      implementation(libs.play.services.maps3d) // Add this line
    }
    
    -   At the end of the file, outside of the `android` and `dependencies`
        blocks, add the secrets configuration:
    
    secrets {
      // Optionally specify a different filename containing your secrets.
      // The plugin defaults to "local.properties"
      propertiesFileName = "secrets.properties"
    
      // A properties file containing default secret values. This file can be
      // checked in version control.
      defaultPropertiesFileName = "local.defaults.properties"
    }
    

Part 2: Add your API key to your project

  1. Create a secrets.properties file:

    • In the app module root directory (usually the app directory), create a new file named secrets.properties.
    • Add your API key to the file:
    MAPS3D_API_KEY=YOUR_API_KEY_HERE
    ``` Note: Make sure you
        replace `YOUR_API_KEY_HERE` with the API key that you configured for use
    with the Maps 3D SDK for Android.
    
  2. Create a local.defaults.properties file: - In the app module root directory, create a new file named secrets.properties. - Add a default or placeholder API key to the file. This file can be checked into version control:

    MAPS3D_API_KEY=DEFAULT_API_KEY_OR_PLACEHOLDER
    

Part 3: Update your AndroidManifest.xml file

  1. Open the app/src/main/AndroidManifest.xml file.

  2. Inside the <application> tag, before the <activity> tag, add the following <meta-data> element to declare your API key:

    <application
      ...>
    
      <meta-data
          android:name="com.google.android.geo.maps3d.API_KEY"
          android:value="${MAPS3D_API_KEY}" />
    
      <activity
          ...>
      </activity>
    </application>
    

    During the build process, the Secrets Gradle Plugin will replace the ${MAPS3D_API_KEY} placeholder with the key from your secrets.properties file.

Next steps

Now that you have a Google Cloud project, API key, and an Android Studio project set up for use with the Maps 3D SDK for Android, you can Add a 3D map to your app.