The Problem:
In earlier versions of Android Studio, developers could create a new project using the Google Maps Activity template. However, in Android Studio Flamingo, this template is missing when creating a new phone and tablet project.
The Solutions:
Solution 1: Create a New Google Maps Views Activity
Although Android Studio Flamingo doesn’t provide a Google Maps Activity project template initially, you can create a Google Maps Views Activity after establishing a new project.
Steps:
- Create a new empty project.
- Right-click on the package where you want to place your activity.
- Select New → Google → Google Maps Views Activity.
Note: Before running your project, remember to obtain your Google Map API key from https://console.cloud.google.com/.
Solution
As you correctly pointed out, Android Studio Flamingo
lacks the ability to create a Google Maps Activity. The link you also provided has a [Look at the code](https://developers.google.com/maps/documentation/android/sdk/start/hl/ru#look-at-the-code)
section which shows the Activity
code, Xml
, and a dependency that needs to be added to your module level build gradle
.
Activity:
internal class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
private lateinit var mMap: GoogleMap
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_maps)
// Obtain the SupportMapFragment and get notified when the map is ready to be used
val mapFragment = supportFragmentManager
.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this)
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
// Add a marker in Sydney and move the camera
val sydney = LatLng(37.4219999,-122.084)
mMap.addMarker(MarkerOptions()
.position(sydney)
.title("Marker in Sydney"))
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
}
}
Xml:
<fragment xmlns="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
Module level build gradle
(Ensure that compileSdk
is set to 33 or higher and minSdk
is set to 21 or higher):
plugins {
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
...
}
dependencies {
implementation 'com.google.android.gms:play-services-maps:18.1.0'
// ...
}
Project level build gradle
:
plugins {
// ...
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.2' apply false
}
Top level settings gradle
:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
// ...
local.properties
:
MAPS_API_KEY=YOUR_API_KEY
AndroidManifest.xml
:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}" />
Solution 3: Use the non-quickstart documentation or download an older version of Android Studio
Android Studio Flamingo does not include a Google Maps Activity template because Google’s documentation has been updated to provide instructions on how to create a Google Maps Activity without the template. Here’s what you can do:
- Follow the non-quickstart documentation: https://developers.google.com/maps/documentation/android-sdk/config
- Alternatively, if you prefer to use the template, you can download an older version of Android Studio that still includes it: https://developer.android.com/studio/releases#older-versions
Q&A
How to create a new project with the Google Maps Activity template on Android Studio Flamingo?
Start New Empty Project, Right Click on the package -> New -> Google -> Google Maps Views Activity
What are the alternative ways to create a Google Maps Activity in Android Studio Flamingo?
Follow the documentation or download an older version of the studio
What are the steps to create a Google Maps Activity in Android Studio?
Create an activity, Add XML, Update build.gradle, Get your API Maps key, Update local.properties, Update AndroidManifest.xml
Video Explanation:
The following video, titled "What's new in Android Studio Flamingo - YouTube", provides additional insights and in-depth exploration related to the topics discussed in this post.
Android Studio Flamingo version 2022.2.1 is now available for download on the stable channel. In this version, you can find improvements for ...
The following video, titled "What's new in Android Studio Flamingo - YouTube", provides additional insights and in-depth exploration related to the topics discussed in this post.
Android Studio Flamingo version 2022.2.1 is now available for download on the stable channel. In this version, you can find improvements for ...