expo: Location.watchPositionAsync() - timeInterval option is not working
š Bug Report
Summary of Issue
When using the Location.watchPositionAsync method, if you input a timeInterval option the callback function will never update. If you input both a timeInterval and a distanceInterval it seems like the timeInterval is ignored entirely.
Environment - output of expo diagnostics & the platform(s) youāre targeting
Expo CLI 3.27.4 environment info: System: OS: Windows 10 10.0.18362 Binaries: Node: 10.16.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.19.1 - ~\AppData\Roaming\npm\yarn.CMD npm: 6.14.8 - C:\Program Files\nodejs\npm.CMD IDEs: Android Studio: Version 4.0.0.0 AI-193.6911.18.40.6626763 npmPackages: expo: ^38.0.10 => 38.0.10 react: ~16.11.0 => 16.11.0 react-dom: ~16.11.0 => 16.11.0 react-native: https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz => 0.62.2 react-native-web: ~0.11.7 => 0.11.7 Expo Workflow: managed
Targeting both iOS and Android, tested on iOS 13.5.1.
Reproducible Demo
await Location.watchPositionAsync(
{
accuracy: Location.Accuracy.BestForNavigation,
timeInterval: 1000,
// distanceInterval: 0,
},
(loc) => {console.log(loc)}
)
Steps to Reproduce
- If you run the above āReproducible Demoā you should see your app print your location into the console once (or sometimes twice for a possibly unrelated bug) and then never update your location again.
- If you comment out the
timeIntervaloption you should experience the same behaviour. - If you enable the
distanceIntervaloption you should now experience a regular stream of location updates into your console (the expected behaviour). - If you enable both the
timeIntervalanddistanceIntervaloptions you should experience the same behaviour as having only thedistanceIntervaloption enabled. - If you play with the
distanceIntervalvalues the option appears to behave as expected.
Expected Behavior vs Actual Behavior
I would expect that when timeInterval is set to 1000 I experience a location update every one second. Instead it seems that the timeInterval option does nothing, behaving the same way as if I had not set the option at all.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 15
- Comments: 30 (4 by maintainers)
Commits related to this issue
- Updates for Live-askPermission — committed to udacity/reactnd-UdaciFitness-complete by tylermcginnis 7 years ago
expo sdk 49 still not working !!
Yeah, Iām still having this same issue. Using timeInterval in startLocationUpdatesAsync for background location does absolutely nothing. It fires once on the very first time when the app loads, and then never again. There is no interval at all; I wish I was having the previously mentioned problem where it was only updating every 15 seconds.
Any updates on this issue yet?
I think I will just use ādistanceIntervalā + a function that uses setTimeout 60secs to request the last location y if the user is no moving, thus, not sending new locations.
Hi @KatancicDenisz, in my case, Iām using background location without maps, so itās not my situation. thanks!
I can confirm the problem exists. The same happens with Expo 39 (tested on Android).
But⦠@ZachThomasAU - as far as I know, the timeInterval option works only for Android so if your target is iOS too then Iām not sure if you should use it. Also, if you tested this on iOS, it wonāt work there.