A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/maps/documentation/android-sdk/ktx below:

Maps Android KTX | Maps SDK for Android

Maps Android KTX

Stay organized with collections Save and categorize content based on your preferences.

Maps Android Kotlin extensions (KTX) are a collection of Kotlin extensions for the Maps SDK for Android and the Maps SDK for Android Utility Library. These extensions provide Kotlin language features that enable you to write concise and idiomatic Kotlin when developing for the Maps SDK for Android. Maps KTX is open-sourced and available on GitHub along with examples.

Installation

To install KTX for the Maps SDK for Android, and optionally for the Maps SDK for Android Utility Library, add the following dependencies to your build.gradle.kts file.

dependencies {

    // KTX for the Maps SDK for Android library
    implementation("com.google.maps.android:maps-ktx:5.2.0")
}
Example Usages

With the KTX library, you can take advantage of several Kotlin language features such as extension functions, named parameters and default arguments, destructuring declarations, and coroutines.

Retrieving a GoogleMap using coroutines

Accessing a GoogleMap can be retrieved using coroutines.

lifecycleScope.launch {
  lifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) {
    val mapFragment: SupportMapFragment? =
      supportFragmentManager.findFragmentById(R.id.map) as? SupportMapFragment
    val googleMap: GoogleMap? = mapFragment?.awaitMap()
  }
}
Adding a marker

Adding a marker can be done using the DSL-style method addMarker().

val sydney = LatLng(-33.852, 151.211)
val marker = googleMap.addMarker {
  position(sydney)
  title("Marker in Sydney")
}
Collecting camera events

Events, such as camera moves, can be collected via Kotlin Flow.

lifecycleScope.launch {
  lifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) {
    googleMap.cameraMoveEvents().collect {
      print("Received camera move event")
    }
  }
}

You can see a full list of supported features by reading the reference documentation.

Try the sample application

The GitHub repository for this library also contains a demo application that shows how you can use the Maps KTX library in your own app.

To try the demo application, follow these steps:

  1. From GitHub, clone the or download the ZIP file.
  2. In Android Studio, choose File -> Open and navigate to the directory and open the folder that you just cloned or downloaded.
  3. Add an API key to the demo app.
    1. Get a Maps SDK for Android key.
    2. In the root directory, create a file called secrets.properties. This file should NOT be under version control to protect your API key.
    3. Add this single line to secrets.properties
      MAPS_API_KEY="YOUR_API_KEY"
      where YOUR_API_KEY is the actual API key you obtained in the first step. You can look at the secrets.defaults.properties as an example.
  4. Under the run configuration, select the module app-ktx.
  5. Select Run 'app-ktx'.
What's next

You may also be interested in other Kotlin extension libraries for Google Maps Platform:

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-14 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-14 UTC."],[[["Maps Android Kotlin extensions (KTX) offer Kotlin features for concise and idiomatic development with the Maps SDK for Android."],["You can add markers, retrieve GoogleMap using coroutines, and collect camera events using Kotlin Flows with Maps KTX."],["The library is open-source and available on GitHub with a demo application showcasing its functionalities."],["Maps KTX can be easily installed by adding a dependency to your `build.gradle.kts` file."],["Other KTX libraries are available for the Maps SDK for Android Utility Library and Places SDK for Android."]]],[]]


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