From e932e53ae57cb22def47164e61f76d9c838c045d Mon Sep 17 00:00:00 2001 From: Chris Arriola Date: Wed, 7 Apr 2021 16:31:24 -0700 Subject: [PATCH] feat: Add groundOverlayClicks() --- .../com/google/maps/android/ktx/GoogleMap.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/maps-ktx/src/main/java/com/google/maps/android/ktx/GoogleMap.kt b/maps-ktx/src/main/java/com/google/maps/android/ktx/GoogleMap.kt index bc5cff0e..17d33223 100644 --- a/maps-ktx/src/main/java/com/google/maps/android/ktx/GoogleMap.kt +++ b/maps-ktx/src/main/java/com/google/maps/android/ktx/GoogleMap.kt @@ -209,6 +209,22 @@ public fun GoogleMap.cameraMoveStartedEvents(): Flow = } } +/** + * Returns a flow that emits when a ground overlay is clicked. Using this to observe ground overlay + * clicks events will override an existing listener (if any) to + * [GoogleMap.setOnGroundOverlayClickListener]. + */ +@ExperimentalCoroutinesApi +public fun GoogleMap.groundOverlayClicks(): Flow = + callbackFlow { + setOnGroundOverlayClickListener { + offerCatching(it) + } + awaitClose { + setOnGroundOverlayClickListener(null) + } + } + /** * Builds a new [GoogleMapOptions] using the provided [optionsActions]. *