Stay organized with collections Save and categorize content based on your preferences.
Create an Android app that displays a map by using the Google Maps Views template for Android Studio. If you have an existing Android Studio project that you'd like to set up, see Set up an Android Studio project.
This quickstart is intended for developers who are familiar with basic Android development with Kotlin or Java.
About the development environmentThis quickstart was developed using Android Studio Hedgehog and the Android Gradle plugin version 8.2.
Note: If your development environment uses a different version of Android Studio or Gradle you might have to modify the steps based on your environment. For more information about Android Studio and Gradle versions, see Android Gradle plugin and Android Studio compatibility. Set up an Android deviceTo run an app that uses the Maps SDK for Android, you must deploy it to an Android device or Android emulator that is based on Android 5.0 or higher and includes the Google APIs.
The procedure to create a Google Maps project in Android Studio was changed in the Flamingo and later releases of Android Studio.
Open Android Studio, and click New Project in the Welcome to Android Studio window.
In the New Project window, under the Phone and Tablet category, select No Activity, and then click Next.
Complete the New Project form:
Set Language to Java or Kotlin. Both languages are fully supported by the Maps SDK for Android. To learn more about Kotlin, see Develop Android apps with Kotlin.
Set Minimum SDK to an SDK version compatible with your test device. You must select a version greater than the minimum version required by the Maps SDK for Android version 19.0.x, which is Android API Level 21 ("Lollipop"; Android 5.0) or higher. See the Release Notes for the latest information on the SDK version requirements.
Note: If you are unsure of what SDK version to choose, select the Help me choose link to display distribution information for supported Android SDKs. For example, if you choose Android API Level 21 ("Lollipop"; Android 5.0), your app should run on over 99% of Android devices.Set the Build configuration language to Kotlin DSL or Groovy DSL. Snippets for both build configurations languages are shown in the following procedures.
Click Finish.
Android Studio starts Gradle and builds the project. This may take some time.
Add the Google Maps Views Activity:
app
folder in your project.Select New > Google > Google Maps Views Activity.
In the New Android Activity dialog box, select the Launcher Activity checkbox.
Select Finish.
For more information, see Add code from a template
When the build is finished, Android Studio opens the AndroidManifest.xml
and MapsActivity
files. Your activity may have a different name, but it is the one you configured during setup.
AndroidManifest.xml
file contains instructions on getting a Google Maps API key and then adding it to your local.properties
file. Do not add your API key to the local.properties
file. Doing so stores your API key less securely. Instead, follow the instructions in Set up your Google Cloud project to create a Cloud project and configure an API key.Complete the required Cloud console setup steps by clicking through the following tabs:
Step 1 ConsoleIn the Google Cloud console, on the project selector page, click Create Project to begin creating a new Cloud project.
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.
gcloud projects create "PROJECT"
Read more about the Google Cloud SDK , Cloud SDK installation , and the following commands:
Note: If you don't plan to keep the resources that you create in a learning exercise, create a project instead of selecting an existing project. After you finish the exercise, you can delete the project, removing all resources associated with the project. Step 2To use Google Maps Platform, you must enable the APIs or SDKs you plan to use with your project.
ConsoleEnable the Maps SDK for Android
Cloud SDKgcloud services enable \ --project "PROJECT" \ "maps-android-backend.googleapis.com"
Read more about the Google Cloud SDK , Cloud SDK installation , and the following commands:
Step 3This 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:
ConsoleGo to the Google Maps Platform > Credentials page.
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:
Add the API key to your appThis section describes how to store your API key so that it can be securely referenced by your app. You should not check your API key into your version control system, so we recommend storing it in the secrets.properties
file, which is located in the root directory of your project. For more information about the secrets.properties
file, see Gradle properties files.
To streamline this task, we recommend that you use the Secrets Gradle Plugin for Android.
Note: See the Secrets Gradle Plugin for Android documentation on GitHub for the latest system requirements and installation instructions.To install the Secrets Gradle Plugin for Android in your Google Maps project:
build.gradle.kts
or build.gradle
file and add the following code to the dependencies
element under buildscript
. Kotlin
buildscript { dependencies { classpath("com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1") } }Groovy
buildscript { dependencies { classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1" } }
build.gradle.kts
or build.gradle
file and add the following code to the plugins
element. Kotlin
plugins { // ... id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") }Groovy
plugins { // ... id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' }
build.gradle.kts
or build.gradle
file, ensure that targetSdk
and compileSdk
are set to 34.secrets.properties
file in your top-level directory, and then add the following code. Replace YOUR_API_KEY
with your API key. Store your key in this file because secrets.properties
is excluded from being checked into a version control system. Note: If the secrets.properties
file does not exist, create it in the same folder as the local.properties
file.
MAPS_API_KEY=YOUR_API_KEY
Create the local.defaults.properties
file in your top-level directory, the same folder as the secrets.properties
file, and then add the following code.
DEFAULT_API_KEY
with your API key.
MAPS_API_KEY=DEFAULT_API_KEY
The purpose of this file is to provide a backup location for the API key if the secrets.properties
file is not found so that builds don't fail. This can happen if you clone the app from a version control system which omits secrets.properties
and you have not yet created a secrets.properties
file locally to provide your API key.
AndroidManifest.xml
file, go to com.google.android.geo.API_KEY
and update the android:value attribute
. If the <meta-data>
tag does not exist, create it as a child of the <application>
tag.
<meta-data android:name="com.google.android.geo.API_KEY" android:value="${MAPS_API_KEY}" />
Note: com.google.android.geo.API_KEY
is the recommended metadata name for the API key. A key with this name can be used to authenticate to multiple Google Maps-based APIs on the Android platform, including the Maps SDK for Android. For backwards compatibility, the API also supports the name com.google.android.maps.v2.API_KEY
. This legacy name allows authentication to the Android Maps API v2 only. An application can specify only one of the API key metadata names. If both are specified, the API throws an exception.
In Android Studio, open your module-level build.gradle.kts
or build.gradle
file and edit the secrets
property. If the secrets
property does not exist, add it.
Edit the properties of the plugin to set propertiesFileName
to secrets.properties
, set defaultPropertiesFileName
to local.defaults.properties
, and set any other properties.
secrets { // To add your Maps API key to this project: // 1. If the secrets.properties file does not exist, create it in the same folder as the local.properties file. // 2. Add this line, where YOUR_API_KEY is your API key: // MAPS_API_KEY=YOUR_API_KEY propertiesFileName = "secrets.properties" // A properties file containing default secret values. This file can be // checked in version control. defaultPropertiesFileName = "local.defaults.properties" }Groovy
secrets { // To add your Maps API key to this project: // 1. If the secrets.properties file does not exist, create it in the same folder as the local.properties file. // 2. Add this line, where YOUR_API_KEY is your API key: // MAPS_API_KEY=YOUR_API_KEY propertiesFileName = "secrets.properties" // A properties file containing default secret values. This file can be // checked in version control. defaultPropertiesFileName = "local.defaults.properties" }
Examine the code supplied by the template. In particular, look at the following files in your Android Studio project.
Maps activity fileThe maps activity file is the main activity for the app, and contains the code to manage and display the map. By default, the file that defines the activity is named MapsActivity.java
or if you set Kotlin as the language for your app, MapsActivity.kt
.
The main elements of the maps activity:
The SupportMapFragment
object manages the lifecycle of the map and is the parent element of the app's UI.
The GoogleMap
object provides access to the map data and view. This is the main class of the Maps SDK for Android. The Map Objects guide describes the SupportMapFragment
and GoogleMap
objects in more detail.
The moveCamera
function centers the map at the LatLng
coordinates for Sydney Australia. The first settings to configure when adding a map are usually the map location and camera settings; such as viewing angle, map orientation, and zoom level. See the Camera and View guide for details.
The addMarker
function adds a marker to the coordinates for Sydney. See the Markers guide for details.
The Module build.gradle.kts
file includes the following maps dependency, which is required by the Maps SDK for Android.
dependencies { // Maps SDK for Android implementation("com.google.android.gms:play-services-maps:19.2.0") }Note: The exact version can change based on the current version of the Maps SDK for Android.
To learn more about managing the Maps dependency, see Versioning.
XML layout fileThe activity_maps.xml
file is the XML layout file that defines the structure of the app's UI. The file is located in the res/layout
directory. The activity_maps.xml
file declares a fragment that includes the following elements:
tools:context
sets the default activity of the fragment to MapsActivity
, which is defined in the maps activity file.android:name
sets the class name of the fragment to SupportMapFragment
, which is the fragment type used in the maps activity file.The XML layout file contains the following code:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />
Deploy and run the app
When you run the app successfully, it will display a map that is centered on Sydney Australia with a marker on the city as seen in the following screenshot.
To deploy and run the app:
Set up a map: This document describes how to set up the initial and runtime settings for your map, such as the camera position, map type, UI components, and gestures.
Add a map to your Android app (Kotlin): This codelab walks you through an app that demonstrates some additional features of the Maps SDK for Android.
Use the Maps Android KTX library: This Kotlin extensions (KTX) library lets you take advantage of several Kotlin language features while using the Maps SDK for Android.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-11 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-11 UTC."],[[["This guide provides a step-by-step process for integrating a Google Map into a new Android application using Android Studio."],["Developers need basic Android knowledge, Android Studio Hedgehog or later, and an Android device or emulator running Android 5.0+ with Google APIs."],["The process involves creating a new project, adding a Google Maps Activity, setting up a Google Cloud project with an API key, and securely adding the API key to the app."],["The resulting application will display a basic Google Map, allowing for further customization and interaction."],["Developers can find more advanced resources for map customization and features within the guide."]]],["The process involves creating a new Android Studio project with no initial activity, configuring it for Google Maps by adding a `Google Maps Views Activity`, and enabling the Maps SDK in a new Google Cloud project. An API key is generated, and added to the application via the `secrets.properties` file using the Secrets Gradle Plugin. The app's layout (`activity_maps.xml`) and `MapsActivity` are configured to display a map, move the camera and add a marker in the desired location. Finally, the app is built and run on an Android device or emulator.\n"]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4