question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Geolocation] watchPosition callback has very unpredictable frequency

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Comments:25 (10 by maintainers)

github_iconTop GitHub Comments

5reactions
yonahforstcommented, Feb 11, 2016

@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}

1reaction
lseicommented, Mar 21, 2017

I’m using the following options for watchPosition and have managed to get pretty frequent updates in iOS Simulator and built onto my iPhone (RN 0.42.3):

{
    enableHighAccuracy: true,
    distanceFilter: 1,
}
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found