watchLocation and getCurrentPosition usage conflicts
See original GitHub issueHi, I am using both features of your package, watchLocation to detect when I am going to far from a reference position, in background, with low battery consumption, and getCurrentPosition from time to time to get an update of my current location (either in foreground or in background).
My issue is that it seems that the options I am using for the watch are overriden by my getPosition call (especially distanceFilter for example) and so my watch becomes crazy after the first getCurrentPositionCall as it does not take a significant filter after.
Is there a way to use both calls without the options being shared?
Thanks for your help.
Watch setup (once for all):
const watchId = Geolocation.watchPosition(
(position) => {
console.log('Geolocation new position:', position);
},
(error) => {
console.log('Geolocation error:', error.message);
},
{
timeout: 15000,
maximumAge: 10000,
enableHighAccuracy: true,
distanceFilter: 50,
interval: 60000,
forceRequestLocation: true
},
);
Get Current Position (sometimes in either foreground or background):
Geolocation.getCurrentPosition(
position => {
console.log('position', position);
},
error => {
console.warn('Location error:', error.message);
},
{
timeout: 15000,
maximumAge: 0,
enableHighAccuracy: true,
distanceFilter: 0,
forceRequestLocation: true,
},
);
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
navigator.geolocation.getCurrentPosition sometimes works ...
On iOS Safari, calls to navigator.geolocation.getCurrentPosition would timeout if I had an active navigator.geolocation.watchPosition function running.
Read more >Geolocation.getCurrentPosition() - Web APIs | MDN
If set to 0 , it means that the device cannot use a cached position and must attempt to retrieve the real current...
Read more >getCurrentPosition() and watchPosition() are deprecated ...
I just wanted to put it out there in case anyone else runs sees this in their Chrome console while doing this workshop....
Read more >Geolocation getCurrentPosition continuously fails if first try ...
In my ionic app i wanna use geolocation with the plugin ... ask for geolocation with watchPosition or getCurrentPosition , you get an...
Read more >navigator.geolocation.getCurrentPosition not working ...
getCurrentPosition called with default options uses maximumAge:0 and ... is allowed to pass from the call to getCurrentPosition() or watchPosition() until ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@OlivierVoyer, I’m trying to implement my own iOS module right now. I’ll try to solve this issue in my implementation. Let me know if you’re willing to test it, and your current xcode & RN version. You can track the progress here https://github.com/Agontuk/react-native-geolocation-service/issues/173.
I’ll update the setup instructions soon.
v5.0.0 is fixing the main issue I described in this thread. Thanks @Agontuk