Skip to content

Bugfix: Improve single-shot location fetching - #23

Merged
marcprux merged 2 commits into
skiptools:mainfrom
fhasse95:single-shot-location-fetching
Oct 4, 2026
Merged

marcprux merged 2 commits into
skiptools:mainfrom
fhasse95:single-shot-location-fetching

Conversation

@fhasse95

@fhasse95 fhasse95 commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

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:

  • REQUIRED: I have signed the Contributor Agreement
  • REQUIRED: I have tested my change locally with swift test
  • OPTIONAL: I have tested my change on an iOS simulator or device
  • OPTIONAL: I have tested my change on an Android emulator or device

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes.
    I 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.

@cla-bot cla-bot Bot added the cla-signed label Oct 3, 2026
@marcprux
marcprux merged commit 38f1319 into skiptools:main Oct 4, 2026
2 checks passed
@fhasse95
fhasse95 deleted the single-shot-location-fetching branch October 4, 2026 14:49
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants