Skip to content

feat(location-flow): add LocationManager and clustering Flow extensions#391

Open
dkhawk wants to merge 1 commit into
feature/flow-extensionsfrom
feature/location-flow-extensions
Open

feat(location-flow): add LocationManager and clustering Flow extensions#391
dkhawk wants to merge 1 commit into
feature/flow-extensionsfrom
feature/location-flow-extensions

Conversation

@dkhawk
Copy link
Copy Markdown
Contributor

@dkhawk dkhawk commented May 27, 2026

This PR introduces comprehensive Kotlin Flow extensions to the maps-utils-ktx library, adding modern reactive APIs for both marker/clustering collections and device location streaming.

This branch is based on the core Flow extensions work and adds LocationManager tracking features.

1. LocationManager Flow Extensions 🗺️📍

Exposed two new subscriber-driven Flow APIs on LocationManager for streaming device coordinates:

  • coarseLocationEvents(): Streams from NETWORK_PROVIDER (falls back to PASSIVE_PROVIDER) with @RequiresPermission(Manifest.permission.ACCESS_COARSE_LOCATION).
  • fineLocationEvents(): Streams precise satellite positioning from GPS_PROVIDER with @RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION).
  • Automatic Subscriber Lifecycle: Subscribes/requests updates only when collected, and automatically unregisters the listener (removeUpdates) immediately when collectors cancel or close.
  • Backward Compatibility: Fully overrides LocationListener callbacks to ensure complete compatibility with minSdkVersion 23.

2. Cluster & Shape Collection Flow Extensions 📦

Added clean Flow wrappers for all major listener callbacks in utility managers:

  • ClusterManager: clusterClickEvents(), clusterItemClickEvents(), clusterInfoWindowClickEvents(), clusterInfoWindowLongClickEvents(), clusterItemInfoWindowClickEvents(), and clusterItemInfoWindowLongClickEvents().
  • Collection Managers: Added clickEvents() to MarkerManager.Collection (plus info window click/long-click flows), PolylineManager.Collection, PolygonManager.Collection, CircleManager.Collection, and GroundOverlayManager.Collection.

3. Robust Asynchronous Unit Tests 🧪

Authored dedicated unit tests validating registration, flow event propagation, and cleanup:

  • LocationManagerTest.kt
  • ClusterManagerTest.kt
  • CollectionManagersTest.kt

Verification Status

  • 100% of unit tests passed successfully with zero failures!

…oarse and fine location

- Implemented LocationManager.coarseLocationEvents() to stream coarse location updates from NETWORK_PROVIDER (fallback to PASSIVE_PROVIDER) using callbackFlow.
- Implemented LocationManager.fineLocationEvents() to stream fine location updates from GPS_PROVIDER using callbackFlow.
- Decorated both extensions with @RequiresPermission to enforce ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION system permissions.
- Handled full LocationListener interface overrides to ensure robust backward compatibility for minSdkVersion 23.
- Ensured location updates start only when the flow is collected and clean up immediately using awaitClose { removeUpdates(listener) } when the collector cancels.
- Authored robust unit tests inside LocationManagerTest.kt verifying correct registration, event emission, and cleanup.
@dkhawk dkhawk changed the base branch from main to feature/flow-extensions May 27, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant