From 00b46163670806f309669db966839b350c7b5cc6 Mon Sep 17 00:00:00 2001 From: lesmaux Date: Wed, 12 Sep 2018 17:00:23 +1200 Subject: [PATCH] Added waypoint markers and polyline. --- App.js | 134 +++++++++++++++++++++++++++------------------------------ 1 file changed, 63 insertions(+), 71 deletions(-) diff --git a/App.js b/App.js index 2125c99..132b390 100644 --- a/App.js +++ b/App.js @@ -22,87 +22,79 @@ const instructions = Platform.select({ 'Shake or press menu button for dev menu', }); -{/**/} -{/**/} - type Props = {}; +let id = 0; export default class App extends Component { constructor(props) { super(props); + this.state = { markers: [] }; + - let ds = new ListView.DataSource({rowHasChanged: (a, b) => a !== b}); - this.state = {dataSource: ds.cloneWithRows([ - 'john', 'joel', 'miki', 'iu lol', 'yeeet', - 'john', 'joel', 'miki', 'iu lol', 'yeeet', - 'john', 'joel', 'miki', 'iu lol', 'yeeet', - 'john', 'joel', 'miki', 'iu lol', 'yeeet', - 'john', 'joel', 'miki', 'iu lol', 'yeeet', - ])}; - setInterval(() => { - // this.distanceInfo.setState({value: Math.random() * 100}); - // this.speedInfo.setState({value: Math.random() * 15}); - // this.directionInfo.setState({value: this.directionInfo.state === 'N' ? 'NW' : 'N'}); + setInterval(() => { + this.distanceInfo.setState({value: Math.random() * 100}); + this.speedInfo.setState({value: Math.random() * 15}); + this.directionInfo.setState({value: this.directionInfo.state === 'N' ? 'NW' : 'N'}); }, 1000); + + let watchID = navigator.geolocation.watchPosition((position) => { + this.setState({ + markers: [ + ...this.state.markers, { + coordinate: position.coords, + key: id++ + } + ] + }, null, {distanceFilter: 1}); + }); + this.state = {markers: [], watchID }; + } + + componentWillUnmount() { + navigator.geolocation.stopWatch(this.state.watchID); } + render() { - return ( - } - renderRow={(row) => ( - - - {row} - - )} - /> -// -// this.setState({text})} -// onBlur={() => this.setState({ text: this.state.text.toUpperCase() })} -// /> -// -// this.setState({confirmedText: this.state.text})} -// onLongPress={() => this.setState({confirmedText: this.state.text.toLowerCase()})} -// > -// Press Me -// -// -// -// {this.state.confirmedText} -// -// -// -// -// this.distanceInfo = info} -// /> -// this.speedInfo = info} -// /> -// this.directionInfo = info} -// /> -// -// + return ( + + this.addMarker((region))} + > + marker.coordinate)} + strokeWidth={5} + /> + {/*{this.state.markers.map((marker) => (*/} + {/**/} + {/*))}*/} + + + + + + this.distanceInfo = info} + /> + this.speedInfo = info} + /> + this.directionInfo = info} + /> + + ); } }