[Geolocation] watchPosition callback has very unpredictable frequency
See original GitHub issueI am building an app that updates the distance from current location, but for some reason I am not getting a consistent callback frequency for navigator.geolocation.watchPosition It seems like something reseting the watch. My code has only componentWillUnmount where it would reset, but I put Alert it never occurred.
Is there frequency parameter I can specify or I guess I am thinking to go with manual timeout approach.
componentDidMount(){
AsyncStorage.getItem('listings')
.then((value) => {
this.state.listings = value?JSON.parse(value):[];
this.state.passProps.listings = this.state.listings;
this.redrawListings();
this.startWatch();
})
.done();
}
componentWillUnmount(){
navigator.geolocation.clearWatch(this.watchID);
}
startWatch(){
this.watchID = navigator.geolocation.watchPosition((lastPosition) => {
this.curLat = lastPosition.coords.latitude;
this.curLon = lastPosition.coords.longitude;
this._updateDistances();
},
(error) => AlertIOS.alert(error),
{enableHighAccuracy: true, timeout: 0, maximumAge: 1000});
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:25 (10 by maintainers)
Top Results From Across the Web
Geolocation.watchPosition() - Web APIs | MDN
The Geolocation method watchPosition() method is used to register a handler function that will be called automatically each time the position ...
Read more >Reduce the frequency of geolocation watchPosition calls
For my use case I check if position has changed more than 100 meters and then update location. I do it with the...
Read more >Safari Technology Preview Release Notes - Apple Developer
If you see bugs or unexpected behavior with the interface of Safari ... Fixed Geolocation API to callback with an error if the...
Read more >geolocation.watchPosition - Apache Cordova
geolocationSuccess : The callback that is called with the current position. · geolocationError: (Optional) The callback that is called if there was an...
Read more >Diff - platform/frameworks/base - android Git repositories
AnimationCallback ); + method public abstract boolean ... behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within ......
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 Free
Top 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

@christopherdro I’ve upgraded to rn 0.20.0-rc1 which should include your update, right? I’m still experiencing a similar issue, where I only get location updates once every ~25 seconds. Even using the following options:
{enableHighAccuracy: true, distanceFilter: 1, timeout: 1000}I’m using the following options for
watchPositionand have managed to get pretty frequent updates in iOS Simulator and built onto my iPhone (RN 0.42.3):