react-native-geolocation
react-native-geolocation copied to clipboard
iOS - maximumAge behaviour seems incorrect
Environment
System: OS: macOS 10.14.6 CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz Memory: 54.35 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 10.16.1 - /usr/local/bin/node npm: 6.9.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3 Android SDK: API Levels: 23, 28, 29 Build Tools: 28.0.3, 29.0.1 System Images: android-26 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom IDEs: Android Studio: 3.5 AI-191.8026.42.35.5791312 Xcode: 10.3/10G8 - /usr/bin/xcodebuild npmPackages: react: ^16.8.6 => 16.9.0 react-native: 0.60.5 => 0.60.5
Platforms
iOS only
Versions
- Android: N/A
- iOS: 12.4
- react-native-geolocation: 2.0.2
- react-native: 0.60.5
- react: 16.9.0
Description
I am finding that when passing a 'maximumAge' of 0 into the options of getCurrentPosition() I am in-fact getting a cached results. Now I went looking into the code to see if I could see what was going on.
My configuration on the JS side looks like this:
{ timeout: 20000, maximumAge: 0 }
When I set a breakpoint in the getCurrentPosition method on the iOS side and look at the options variable you can see the maximumAge has been set to Infinity.
Now if we look at the (RNCGeolocationOptions)RNCGeolocationOptions:(id)json part of the code.
It looks as if this line: [RCTConvert NSTimeInterval:options[@"maximumAge"]] ?: INFINITY;
is converting our 0 to Infinity.
You can see this in the screenshot below:
Now according to the documentation: "If set to 0, it means that the device cannot use a cached position and must attempt to retrieve the real current position. If set to Infinity the device will always return a cached position regardless of its age.". So to me it looks as if we are converting our 0 to Infinity then we will be returning a cached version.
I can see this behaviour in action by adding a breakpoint to line 316 which returns our cached version. When the maximumAge is set to 0 then this line is hit, if I set it to a small number like 0.001 then the breakpoint is not hit and we carry on to make an actual geo location request.
I had a look at the history on Github and these files have not been touched in a long time so I might be barking up the wrong tree but something feels a little off.
Happy to provide more information if it helps.
I'm experiencing the same problem. I have maximumAge set to 0 and I'm getting a cached result on iOS only. On Android it works as expected always performing a new fix.
This community is very unsupportive.
@stephenheron I am seeing this behavior as well, it looks like you found the bug though - did you open a pr for it?
does we found any solution for it ?
Did anyone find any workaround for this issue? I'm still getting cached result even though I'm setting maximumAge to 0...
Did you found any solution for that?
This worked for me on both platforms @fistofzen:
IOS - disable cache : { enableHighAccuracy: true } Android - 2 seconds cache limit : { enableHighAccuracy: true, maximumAge: 2000 }
I'm using version 5.3.1