React-native: geolocation.watchPosition() - subscription.listener.apply is not a function

Created on 20 Aug 2016  路  5Comments  路  Source: facebook/react-native

Environment

  • React Native 0.31.0
  • OSX 10.11.6
  • iOS Emulator 9.6 (doesn't happen on Android)

    The code

class MyComponent extends Component {
  constructor() {
    super();
    this.state = {};
  }

  componentDidMount() {
    this.watcher = navigator.geolocation.watchPosition(
      pos => this.setState(pos.coords);
    );
  }

  componentWillUnmount() {
    navigator.geolocation.clearWatch(this.watcher);
  }

  render() {
    return (
      <Text>{this.state.latitude}</Text> 
    );
  }
}

Steps to reproduce

  1. Load the app in an iOS emulator (9.6). Coords load fine.
  2. Change the location _Debug -> Location -> ..._. Coords load fine.
  3. Change the location again. You should see: subscription.listener.apply is not a function
Ran Commands Locked

Most helpful comment

For people encountering this later... I ran into this as well because I passed a position options object without an error handler. If you do so, the eventEmitter will try to run your options object as the error handler function. Also, this means that your options aren't being processed properly without an error handler, so if you need to send options to watchPosition, make sure to send the semi-optional error handler as well.

All 5 comments

@facebook-github-bot label Icebox

Hi there! This issue is being closed because it has been inactive for a while.

But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/geolocationwatchposition-subscriptionlistenerapply-is-not-a-function

ProductPains helps the community prioritize the most important issues thanks to its voting feature.
It is easy to use - just login with GitHub.

Also, if this issue is a bug, please consider sending a PR with a fix.
We're a small team and rely on the community for bug fixes of issues that don't affect fb apps.

@facebook-github-bot close

@charpeni tells me to close this issue. If you think it should still be opened let us know why.

For people encountering this later... I ran into this as well because I passed a position options object without an error handler. If you do so, the eventEmitter will try to run your options object as the error handler function. Also, this means that your options aren't being processed properly without an error handler, so if you need to send options to watchPosition, make sure to send the semi-optional error handler as well.

Was this page helpful?
0 / 5 - 0 ratings