Tagging notes with geolocation
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 ...
Get React: Building Modern Web Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.