Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

fix iOS returning old location when maximumAge is set #96

Merged
merged 2 commits into from
Dec 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/geolocation.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,13 @@ export function getCurrentLocation(options: Options): Promise<Location> {
};

let successCallback = function (location: Location) {
stopTimerAndMonitor(locListener.id);
if (typeof options.maximumAge === "number") {
if (location.timestamp.valueOf() + options.maximumAge > new Date().valueOf()) {
resolve(location);
} else {
reject(new Error("New location is older than requested maximum age!"));
}
} else {
resolve(location);
if (typeof options.maximumAge === "number" && location.timestamp.valueOf() + options.maximumAge < new Date().valueOf()) {
// returned location is too old, but we still have some time before the timeout so maybe wait a bit?
return;
}

stopTimerAndMonitor(locListener.id);
resolve(location);
};

locListener = LocationListenerImpl.initWithLocationError(successCallback);
Expand Down