arch-anx1ety opened a new issue, #295:
URL: https://github.com/apache/cordova-plugin-geolocation/issues/295

   # Bug Report
   
   ## Problem
   CDVLocation.m ignores the `maximumAge` parameter passed from the JS layer, 
causing stale cached positions to be returned even when `maximumAge: 0` is 
specified.
   
   ### What is expected to happen?
   When `navigator.geolocation.getCurrentPosition(success, error, { maximumAge: 
0 })` is called, the plugin should only return a position whose age (current 
time minus position timestamp) is within the `maximumAge` window. With 
`maximumAge: 0`, the plugin should reject any cached position and wait for a 
fresh GPS fix from `CLLocationManager`, per the [W3C Geolocation specification 
§6.3](https://www.w3.org/TR/geolocation/#dom-positionoptions-maximumage):
   
   > "If the implementation does not have a cached position available whose age 
is no greater than the specified `maximumAge`, then it must acquire a new 
position."
   
   The JS layer (`www/geolocation.js` line 147) correctly passes `maximumAge` 
as argument index 1 to the native side:
   
   exec(win, fail, 'Geolocation', 'getLocation', [options.enableHighAccuracy, 
options.maximumAge]);
   
   
   ### What does actually happen?
   CDVLocation.m getLocation: (line 193) never reads argument index 1. Only 
enableHighAccuracy (index 0) is extracted:
   
   // Line 197 — the ONLY argument read:
   BOOL enableHighAccuracy = [[command argumentAtIndex:0] boolValue];
   
   First CLLocationManager callback is thus accepted unconditionally — In 
didUpdateToLocation:fromLocation: (line 167), the first position received is 
stored and returned to all waiting callbacks without checking its age:
   
   cData.locationInfo = newLocation;  // No age check — line 173
   The first callback from CLLocationManager after startUpdatingLocation is 
always the locationd daemon's cached position, which can be minutes or hours 
old.
   
   Real-world impact: Field sales reps physically present at a store are told 
they are 2-3 miles away because the GPS position from their last outdoor 
location persists indefinitely. The position returned in 4-5ms (impossible for 
real GPS acquisition) with maximumAge: 0 and timeout: 20000.
   
   
   ## Information
   <!-- Include all relevant information that might help understand and 
reproduce the problem -->
   
   1. Walk outdoors and let the iPhone acquire a solid GPS fix at Location A 
(verify in Apple Maps — high accuracy, ~5m)
   2. Move indoors to Location B (a building interior where GPS signal is 
blocked, >500m from Location A)
   3. Wait 2-3 minutes for the GPS fix to go stale
   4. Call navigator.geolocation.getCurrentPosition(success, error, { 
maximumAge: 0, timeout: 20000, enableHighAccuracy: true })
   5. Result: The success callback fires in <10ms with Location A's 
coordinates, not Location B
   6. Call again — same stale Location A coordinates returned
   7. Restart the app — call again — still Location A
   
   Why this is hard to reproduce casually: If the tester is stationary or 
outdoors with GPS signal, the locationd cache happens to be approximately 
correct, making the stale position indistinguishable from a fresh one. The bug 
manifests when the user moves indoors after having an outdoor GPS fix.
   
   ### Command or Code
   <!-- What command or code is needed to reproduce the problem? -->
   
   navigator.geolocation.getCurrentPosition(
     pos => {
       console.log('Position:', pos.coords.latitude, pos.coords.longitude);
       console.log('Accuracy:', pos.coords.accuracy, 'm');
       console.log('Timestamp:', new Date(pos.timestamp));
     },
     err => console.error('Error:', err.code, err.message),
     { maximumAge: 0, timeout: 20000, enableHighAccuracy: true }
   );
   
   
   ### Environment, Platform, Device
   <!-- In what environment, on what platform or on which device are you 
experiencing the issue? -->
   
   Platform: iOS only (Android has a separate native implementation that is not 
affected)
   Devices: Any iPhone or cellular iPad with a GPS chip
   iOS versions tested: iOS 17, iOS 18
   Not reproducible on: WiFi-only iPads (no GPS chip — they use WiFi 
positioning which doesn't have the same caching behavior)
   
   
   ### Version information
   <!-- 
   What are relevant versions you are using?
   For example:
   Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins 
   Other Frameworks: Ionic Framework and CLI version
   Operating System, Android Studio, Xcode etc.
   -->
   
   cordova-plugin-geolocation: 5.0.0
   cordova-ios: 7.1.1
   cordova-android: 13.0.0 (not affected)
   Xcode: 26.0.1
   Cordova CLI: 12.x
   
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [x] I searched for existing GitHub issues
   - [x] I updated all Cordova tooling to most recent version
   - [x] I included all the necessary information above
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to