react-native/Examples/UIExplorer/GeoLocationExample.js
Christopher Chedeau 7060141247 Updates from Mon Mar 2
- [ReactNative] Move merge & mergeInto from downstream to vendor | Christopher Chedeau
- [ReactNative] Replace all the call sites of mergeInto by Object.assign | Christopher Chedeau
- [WIP] Migrated View Managers over to new architecture | Nick Lockwood
- [ReactNative] Replace all the call sites of copyProperties by Object.assign | Christopher Chedeau
- [ReactNative] Migrate navigator.geolocation to open source | Christopher Chedeau
- [ReactNative] Remove README.md, LICENSE and .travis.yml from fbobjc | Christopher Chedeau
- [react-packager] Better transform errors | Amjad Masad
- [React Native][react-packager] Fix test runner and fialing tests | Amjad Masad
2015-03-02 11:36:55 -08:00

73 lines
1.5 KiB
JavaScript

/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule GeoLocationExample
*/
/* 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 <GeoLocationExample />;
},
}
];
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 (
<View>
<Text>
<Text style={styles.title}>Initial position: </Text>
{JSON.stringify(this.state.initialPosition)}
</Text>
<Text>
<Text style={styles.title}>Current position: </Text>
{JSON.stringify(this.state.lastPosition)}
</Text>
</View>
);
}
});
var styles = StyleSheet.create({
title: {
fontWeight: 'bold',
},
});