/** * Copyright 2004-present Facebook. All Rights Reserved. */ /* eslint no-console: 0 */ 'use strict'; var React = require('react-native'); var { StyleSheet, Text, View, } = React; exports.framework = 'React'; exports.title = 'Geolocation'; exports.description = 'Examples of using the Geolocation API.'; exports.examples = [ { title: 'navigator.geolocation', render: function() { return ; }, } ]; var GeolocationExample = React.createClass({ getInitialState: function() { return { initialPosition: 'unknown', lastPosition: 'unknown', }; }, componentDidMount: function() { navigator.geolocation.getCurrentPosition( (initialPosition) => this.setState({initialPosition}), (error) => console.error(error) ); this.watchID = navigator.geolocation.watchPosition((lastPosition) => { this.setState({lastPosition}); }); }, componentWillUnmount: function() { navigator.geolocation.clearWatch(this.watchID); }, render: function() { return ( Initial position: {JSON.stringify(this.state.initialPosition)} Current position: {JSON.stringify(this.state.lastPosition)} ); } }); var styles = StyleSheet.create({ title: { fontWeight: 'bold', }, });