fix(ios): honor maximumAge in getCurrentPosition instead of returning stale cached positions#90
Open
binikingi wants to merge 1 commit into
Open
fix(ios): honor maximumAge in getCurrentPosition instead of returning stale cached positions#90binikingi wants to merge 1 commit into
binikingi wants to merge 1 commit into
Conversation
… stale cached positions
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.
Description
On iOS,
getCurrentPositionignores themaximumAgeoption entirely and can resolve with a stale cached position. This PR makes the iOS implementation honormaximumAgeas documented (and as Android and Web already do): a position older thanmaximumAgeno longer satisfiesgetCurrentPosition— the call stays pending while a fresh position is acquired (falling back to continuous updates when needed), still bounded by the existingtimeouthandling.Details of the change:
maximumAgeis now read fromgetCurrentPositioncalls (stored alongside the existing sharedtimeout, same last-caller-wins semantics).maximumAgebefore resolving pending single-location calls. Because CLLocation timestamps lag delivery by the acquisition time, positions younger than a 5s freshness threshold are always accepted, so the defaultmaximumAge: 0keeps resolving with freshly acquired fixes.Context
There are two ways iOS currently hands back stale coordinates:
CLLocationManager.requestLocation()frequently delivers the system's last known location — taken minutes earlier, before the device moved — and nothing checks its timestamp.requestSingleLocationreturns the in-memorycurrentLocationverbatim whenever monitoring is active, with no freshness check at all.Either way the position carries its original (good) accuracy value, so callers have no signal that the coordinates are outdated. In our production home-care app, caregivers clocking in at a patient's home get positions 1.5–3 miles away — reported as
accuracy: ~16m— because the fix predates their drive over.This is very likely the same root cause behind #68 and #69 ("wrong coordinates on iOS, fine on Android/Web"), both closed for lack of response. The answer to the question asked there ("are you receiving outdated location?") is yes: the coordinates are outdated, and only
position.timestampreveals it.Type of changes
Platforms affected
Tests
npm run verify:ios(xcodebuild) builds successfully.nestingwarnings onGeolocationConstants.swiftpre-date this change).IONGLOCServicefake) if you can point me at the preferred approach.getCurrentPositioncall issued right after arriving at a new location waits for a live fix instead of resolving with the pre-drive cached position.Screenshots (if appropriate)
Checklist