0

My code has, in the React.createClass() call:

  watchID: (null: ?number),
  componentDidMount: function() {
    navigator.geolocation.getCurrentPosition(
      (initialPosition) => this.setState({initialPosition}),
      (error) => console.error(error),
      (position) => this.setState({position}),
      {enableHighAccuracy: false, timeout: 20000, maximumAge: 60 * 60 * 1000});
    this.watchID = navigator.geolocation.watchPosition((lastPosition) =>
      this.setState({lastPosition}));
  },

This is generating the error message Argument 0 (RCTLocationOptions of RCTLocationObserver.getCurrentPosition must not be null.

Is there a problem with the initialPosition arrow function? Also, how can I replace the initialPosition argument with an appropriate anonymous function that will set the initial position to both the initial and last position (being both the initial and the last position), and call a this.fetchData()?

(Feel free to explain anything I'm missing about arrow functions...)

Thanks,

Christos Hayward
  • 5,777
  • 17
  • 58
  • 113
  • 1
    Looks like the you are not passing the arguments in the the right order? I'm not familiar with react native: https://github.com/facebook/react-native/blob/master/Libraries/Geolocation/RCTLocationObserver.m#L194-L196 – Felix Kling Sep 11 '15 at 21:58

1 Answers1

0

The third argument, (position) => this.setState({position}), was the culprit. It expected a (possibly optional AFAIK) hash of options in that spot.

Christos Hayward
  • 5,777
  • 17
  • 58
  • 113