Skip to content

feat(location): add multiplatform Location, LocationSource, and iOS CLLocationManager Flow helpers - #1817

Merged
kikoso merged 5 commits into
feat/experimental-kmp-clusteringfrom
feat/kmp-location-flow
Oct 12, 2026
Merged

kikoso merged 5 commits into
feat/experimental-kmp-clusteringfrom
feat/kmp-location-flow

Conversation

@dkhawk

@dkhawk dkhawk commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Extends the com.google.maps.android.location package in :library to Kotlin Multiplatform (commonMain, androidMain, and iosMain):

  • commonMain (Location.kt):
    • Introduces zero-allocation expect class Location with multiplatform extension properties (latitude, longitude, accuracyMeters, altitudeMeters, bearingDegrees, speedMetersPerSecond, timestampMillis, and latLng: LatLng).
    • Adds LocationPriority (HIGH_ACCURACY, BALANCED_POWER_ACCURACY, LOW_POWER) and fun interface LocationSource returning a cold Flow<Location>.
    • Promotes kotlinx-coroutines-core to commonMain api dependencies so Flow<Location> can be consumed directly in shared code.
  • androidMain (Location.android.kt, LocationManager.kt, FusedLocationProvider.kt):
    • Maps actual typealias Location = android.location.Location for 100% source and binary compatibility with existing Android callers.
    • Adds LocationManager.asLocationSource() and FusedLocationProviderClient.asLocationSource() (kept in FusedLocationProvider.kt so consumers without the optional play-services-location dependency do not encounter class-loading errors).
    • Handles SecurityException in coarseLocationEvents, fineLocationEvents, and FusedLocationProviderClient.locationEvents by closing the callbackFlow cleanly when permissions are missing or revoked at runtime.
  • iosMain (Location.ios.kt):
    • Maps actual typealias Location = platform.CoreLocation.CLLocation.
    • Adds CLLocationManager.locationEvents(), coarseLocationEvents(), fineLocationEvents(), and asLocationSource() backed by callbackFlow and CLLocationManagerDelegateProtocol.

Testing

  • :library:testAndroidHostTest (LocationSourceTest, LocationManagerTest, FusedLocationProviderTest)
  • :library:iosSimulatorArm64Test (CLLocationManagerTest)
  • :library:apiCheck

@googlemaps-bot

googlemaps-bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Code Coverage

Overall Project 60.88% -0.13% 🍏
Files changed 73.89% 🍏

Module Coverage
Kover Gradle Plugin XML report for :library 89.08% -0.79% 🍏
Files
Module File Coverage
Kover Gradle Plugin XML report for :library LocationManager.kt 85.71% 🍏
Location.android.kt 76.56% -23.44% 🍏
Location.kt 73.81% -26.19% 🍏
FusedLocationProvider.kt 69.29% -19.29% ❌

@kikoso kikoso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition, and the typealias approach keeps the Android side really clean! Can you take a look at the comments, @dkhawk ? The permission one is the most important, since it changes the behaviour of APIs we already ship in 6.0.0.

Comment thread library/src/iosMain/kotlin/com/google/maps/android/location/Location.ios.kt Outdated
… delegate

- Android location flows fail with SecurityException again when location
  permission is missing, as in 6.0.0, instead of completing silently.
- iOS locationEvents restores the delegate the manager had before
  collection, and documents the single-collector limitation.
- iOS altitudeMeters reads ellipsoidalAltitude (WGS 84), matching Android's
  getAltitude(); CLLocation.altitude is above mean sea level.

@kikoso kikoso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @dkhawk .

@kikoso
kikoso merged commit f9a38c4 into feat/experimental-kmp-clustering Oct 12, 2026
6 checks passed
@kikoso
kikoso deleted the feat/kmp-location-flow branch October 12, 2026 03:47
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.

3 participants