June 2016
Intermediate to advanced
910 pages
18h 59m
English
Let's take geolocation for a spin and start capturing the user's location when they save a new note. Since we're going to be using the location data when we save notes, we'll add our code to the ReactNotes component in index.ios.js or index.android.js. Let's begin by adding a function called trackLocation():
class ReactNotes extends React.Component {
trackLocation() {
navigator.geolocation.getCurrentPosition(
(initialPosition) => this.setState({initialPosition}),
(error) => alert(error.message)
);
this.watchID = navigator.geolocation.watchPosition((lastPosition) => {
this.setState({lastPosition});
});
}
…
}Here we call getCurrentPosition and provide a callback that will update the current state with the position information ...
Read now
Unlock full access