Repository navigation
Bugfix: Improve single-shot location fetching - #23
Merged
Merged
Conversation
marcprux
approved these changes
Oct 4, 2026
4 of 5 tasks
marcprux
pushed a commit
that referenced
this pull request
Oct 15, 2026
…rval (#21) * Give LocationProvider.monitor() control over request quality and interval `monitor()` built its Android request as `LocationRequest.Builder(1_000).build()` with an explicit `// TODO: setQuality, etc.`, so callers had no way to ask for anything other than the platform default: - `setQuality(...)` was never called, leaving `QUALITY_BALANCED_POWER_ACCURACY`, which resolves fixes from wifi/cell as well as GNSS. - The interval was hardcoded to 1s with no way to change it — and since the interval is only ever a *desired* rate, `setQuality` is the lever that actually determines how often fixes arrive. - `setMinUpdateIntervalMillis(...)` was never called either, so callers could not bound the delivery rate from the fast side. - The Darwin leg never set `desiredAccuracy`, so there was no equivalent of `kCLLocationAccuracyBestForNavigation`. Add a `LocationQuality` hint plus `interval` / `minimumInterval` parameters, mapping onto `LocationRequest.QUALITY_*` and `setMinUpdateIntervalMillis` on Android and `desiredAccuracy` on Darwin. All three parameters are defaulted and `platformDefault` deliberately leaves each platform's own default untouched — Android's `LocationRequest` defaults to balanced power while `CLLocationManager` defaults to `kCLLocationAccuracyBest`, so unifying them would be a behaviour change. Existing call sites compile and behave exactly as before. The new Android calls are all API 31, the same level as the `LocationRequest.Builder` and `FUSED_PROVIDER` already in use here, so the effective API floor is unchanged. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * Surface whether a fix actually carried speed / accuracy `LocationEvent` flattens absent readings to `0.0`, which for speed is indistinguishable from a genuinely stationary device. That is not a theoretical concern: on Android a fix resolved from wifi/cell rather than GNSS routinely reports `Location.hasSpeed() == false`, so a balanced-power stream can report `speed == 0.0` continuously while the device is moving at road speed. Any speed-based logic silently reads that as "stopped". The information is already computed and then discarded — the Android initialiser calls `hasAccuracy()` / `hasSpeed()` / `hasSpeedAccuracy()` purely to pick between the value and `0.0`. Keep those results. This also normalises a genuine cross-platform difference that callers would otherwise have to know about: Android signals "absent" with `hasX() == false`, while CoreLocation signals it with a negative value. Both now map onto the same flag. Additive only — the existing properties keep their current values and meanings, and the memberwise initialiser is internal, so no call site changes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * Give fetchCurrentLocation() the same request-quality control as monitor() The previous commit gave `monitor()` a quality knob but left the single-shot path untouched, so `fetchCurrentLocation()` still had no way to ask for anything but the platform default. That was not simply a missing parameter. The Android leg used `requestSingleUpdate`, which is deprecated (API 30) and accepts no `LocationRequest` at all, so there was nowhere to put a quality hint. It now uses `requestLocationUpdates` with a listener that removes itself on the first fix, the same call shape `monitor()` already uses. The request construction is shared between the two paths so they cannot drift. On Darwin, `quality` sets `desiredAccuracy` before `requestLocation()`, falling back to the existing NearestTenMeters. A caller that names a quality always gets a fresh fix. The last-known location shortcut (#23) is kept for `platformDefault` only: a cached fix can be minutes old and resolved from wifi or cell, which is not what a caller asking for `.navigation` wants. `quality` defaults to `platformDefault`, so existing call sites compile and behave exactly as before. The single-shot interval is 0, which only governs how quickly the first fix arrives, since updates stop after it. No API-level change: `requestLocationUpdates(String, LocationRequest, Executor, LocationListener)` is API 31, the same floor `LocationRequest.Builder` and `FUSED_PROVIDER` already imposed here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Aecasorg <19954019+Aecasorg@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves
LocationProvider.fetchCurrentLocation()reliability and performance on both platforms.On iOS, single-shot location requests are now performed from the main actor and use
requestLocation()instead of starting continuous location updates. Recent cached locations are reused when available, avoiding unnecessary delays while still falling back to a fresh location request when the cached location is stale.On Android,
fetchCurrentLocation()similarly checks available last-known locations first and only uses them when they are sufficiently recent. Otherwise, it falls back to a fresh single-shot location request.Thank you for contributing to the Skip project! Please use this space to describe your change and add any labels (bug, enhancement, documentation, etc.) to help categorize your contribution.
Please review the contribution guide at https://skip.dev/docs/contributing/ for advice and guidance on making high-quality PRs.
Skip Pull Request Checklist:
swift testI used Codex to generate the initial version of the changes, then iteratively refined them myself and manually validated the behavior in my own app, which uses the user's current location.