Maps SDK for Android Quickstart Stay organized with collections Save and categorize content based on your preferences.
AI-generated Key Takeaways
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.
Create an Android app that displays a map by using the Google Maps Viewstemplate for Android Studio. If you have an existing Android Studio project thatyou'd like to set up, seeSet up an Android Studio project.
This quickstart is intended for developers who are familiar with basicAndroid development with Kotlin or Java.
About the development environment
This quickstart was developed usingAndroid StudioHedgehog and theAndroidGradle pluginversion 8.2.
Note: If your development environment uses a different version of Android Studioor Gradle you might have to modify the steps based on your environment. For moreinformation about Android Studio and Gradle versions, seeAndroid Gradle pluginand Android Studiocompatibility.Set up an Android device
To 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.
- To use an Android device, follow the instructions atRun apps on a hardware device.
- To use an Android emulator, you can create a virtual device and install the emulator by using theAndroid Virtual Device (AVD) Manager that comes with Android Studio.Note:If you choose to use an Android emulator, ensure that you choose a device with thePlay icon,
, displayed under thePlay Store column. This icon indicates that these profiles are fullyCTS compliant and may use system images that include the Play Store app:
Create a Google Maps project in Android Studio
The procedure to create a Google Maps project in Android Studio was changed inthe Flamingo and later releases of Android Studio.
Open Android Studio, and clickNew Project in theWelcome to Android Studio window.
In theNew Project window, under thePhone and Tablet category,selectNo Activity, and then clickNext.
Complete theNew Project form:
SetLanguage to Java or Kotlin. Both languages are fully supported bythe Maps SDK for Android. To learn more about Kotlin, seeDevelop Android apps with Kotlin.
SetMinimum SDK to an SDK version compatible with your test device.You must select a version greater than the minimum version required by theMaps SDK for Android version 19.0.x,which is Android API Level 21 ("Lollipop"; Android 5.0) or higher.See theRelease Notes forthe latest information on the SDK version requirements.
Note: If you are unsure of what SDK version to choose, select theHelp me choose link to display distribution information for supportedAndroid SDKs. For example, if you chooseAndroid API Level 21 ("Lollipop"; Android 5.0), your app should run on over99% of Android devices.Set theBuild configuration language to Kotlin DSL or Groovy DSL.Snippets for both build configurations languages are shown in the followingprocedures.
ClickFinish.
Android Studio starts Gradle and builds the project. This may take some time.
Add theGoogle Maps Views Activity:
- Right-click on the
appfolder in your project. SelectNew > Google > Google Maps Views Activity.

In theNew Android Activity dialog box, select theLauncher Activity checkbox.
SelectFinish.
For more information, seeAdd code from a template
- Right-click on the
When the build is finished, Android Studio opens the
Caution: TheAndroidManifest.xmlandMapsActivityfiles. Your activity may have a different name, but itis the one you configured during setup.AndroidManifest.xmlfile contains instructions on getting aGoogle Maps API key and then adding it to yourlocal.propertiesfile.Donot add your API key to thelocal.propertiesfile.Doing so stores your API key less securely. Instead, follow the instructionsinSet up your Google Cloud project to create a Cloud project andconfigure an API key.
Set up your Google Cloud project
Complete the required Cloud console setup steps by clickingthrough the following tabs:
Step 1
Console
In the Google Cloud console, on the project selector page, clickCreate 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, seeBilling account credits andBilling.
Cloud SDK
gcloudprojectscreate"PROJECT"Read more about theGoogle 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.
Console
Cloud SDK
gcloudservicesenable\--project"PROJECT"\"maps-android-backend.googleapis.com"
Read more about theGoogle Cloud SDK ,Cloud SDK installation , and the following commands:
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-specificUsing 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
Go to theGoogle Maps Platform > Credentials page.
- On theCredentials page, clickCreate credentials > API key.
TheAPI key created dialog displays your newly created API key. - ClickClose.
The new API key is listed on theCredentials page underAPI keys.
(Remember torestrict the API key before using it in production.)
Cloud SDK
gcloudservicesapi-keyscreate\--project"PROJECT"\--display-name"DISPLAY_NAME"
Read more about theGoogle Cloud SDK ,Cloud SDK installation , and the following commands:
Add the API key to your app
This section describes how to store your API key so that it can be securely referenced byyour app. You should not check your API key into your version control system, so we recommendstoring it in thesecrets.properties file, which is located in the root directory of yourproject. For more information about thesecrets.properties file, seeGradle properties files.
To streamline this task, we recommend that you use theSecrets Gradle Plugin for Android.
Note:See theSecrets 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:
- In Android Studio, open your top-level
build.gradle.ktsorbuild.gradlefile and add the following code to thedependencieselement underbuildscript.Kotlin
plugins {alias(libs.plugins.android.application) apply falsealias(libs.plugins.jetbrains.kotlin.android) apply falsealias(libs.plugins.kotlin.compose) apply falsealias(libs.plugins.secrets.gradle.plugin) apply false}
Groovy
buildscript {dependencies {classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1"}}
- Open your module-level
build.gradle.ktsorbuild.gradlefile and add the following code to thepluginselement.Kotlin
plugins{// ...alias(libs.plugins.secrets.gradle.plugin)}
Groovy
plugins {// ...id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'}
- In your module-level
build.gradle.ktsorbuild.gradlefile, ensure thattargetSdkandcompileSdkare set to 34. - Sync your project with Gradle.
- Open the
secrets.propertiesfile in your top-level directory, and then add the following code. ReplaceYOUR_API_KEYwith your API key. Store your key in this file becausesecrets.propertiesis excluded from being checked into a version control system.Note:If thesecrets.propertiesfile does not exist, create it in the same folder as thelocal.propertiesfile.MAPS_API_KEY=YOUR_API_KEY
Create the
Note:Enter the code as shown. Don't replacelocal.defaults.propertiesfile in your top-level directory, the same folder as thesecrets.propertiesfile, and then add the following code.DEFAULT_API_KEYwith 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.propertiesfile is not found so that builds don't fail. This can happen if you clone the app from a version control system which omitssecrets.propertiesand you have not yet created asecrets.propertiesfile locally to provide your API key.- In your
AndroidManifest.xmlfile, go tocom.google.android.geo.API_KEYand update theandroid:value attribute. If the<meta-data>tag does not exist, create it as a child of the<application>tag.<meta-dataandroid:name="com.google.android.geo.API_KEY"android:value="${MAPS_API_KEY}"/>
Note:
com.google.android.geo.API_KEYis 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 namecom.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.ktsorbuild.gradlefile and edit thesecretsproperty. If thesecretsproperty does not exist, add it.Edit the properties of the plugin to set
propertiesFileNametosecrets.properties, setdefaultPropertiesFileNametolocal.defaults.properties, and set any other properties.Kotlin
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_KEYpropertiesFileName="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_KEYpropertiesFileName="secrets.properties"// A properties file containing default secret values. This file can be// checked in version control.defaultPropertiesFileName="local.defaults.properties"}
Look at the code
Examine the code supplied by the template. In particular, look at the followingfiles in your Android Studio project.
Maps activity file
The maps activity file is the mainactivity for the app, andcontains the code to manage and display the map. By default, the file thatdefines the activity is namedMapsActivity.java or if you set Kotlin as thelanguage for your app,MapsActivity.kt.
The main elements of the maps activity:
The
SupportMapFragmentobject manages thelifecycle of the map and is the parent element of the app's UI.The
GoogleMapobject provides access to the map data andview. This is the main class of the Maps SDK for Android. TheMap Objectsguide describes theSupportMapFragmentandGoogleMapobjects in moredetail.The
moveCamerafunction centers the map at theLatLngcoordinates for Sydney Australia. The first settings toconfigure when adding a map are usually the map location and camera settings;such as viewing angle, map orientation, and zoom level. See theCamera and View guide for details.The
addMarkerfunction adds a marker to the coordinates forSydney. See theMarkers guide for details.
Module Gradle file
The Modulebuild.gradle.kts file includes the following maps dependency, whichis required by the Maps SDK for Android.
dependencies{// Maps SDK for Androidimplementation(libs.play.services.maps)}
To learn more about managing the Maps dependency, seeVersioning.
XML layout file
Theactivity_maps.xml file is theXML layout file that defines thestructure of the app's UI. The file is located in theres/layout directory.Theactivity_maps.xml file declares a fragment that includes the followingelements:
tools:contextsets the default activity of the fragmenttoMapsActivity, which is defined in the maps activity file.android:namesets the class name of the fragment toSupportMapFragment, which is the fragment type used in the maps activityfile.
The XML layout file contains the following code:
<fragmentxmlns: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 onSydney Australia with a marker on the city as seen in the following screenshot.
To deploy and run the app:
- In Android Studio, click theRun menu option (or the play button icon) to run your app.
- When prompted to choose a device, choose one of the following options:
- Select the Android device that's connected to your computer.
- Alternatively, select theLaunch emulator radio button and choose the virtual device that you set up.
- ClickOK. Android Studio will start Gradle to build your app, and then display the results on your device or emulator. It can take several minutes before the app launches.
Next steps
Set up a map: This documentdescribes how to set up the initial and runtime settings for your map, suchas the camera position, map type, UI components, and gestures.
Add a map to your Android app (Kotlin): This codelabwalks you through an app that demonstrates some additional features of theMaps SDK for Android.
Use the Maps Android KTX library:This Kotlin extensions (KTX) library lets you take advantage of severalKotlin language features while using the Maps SDK for Android.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-10-31 UTC.