-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
95 lines (88 loc) · 2.2 KB
/
Copy pathApp.js
File metadata and controls
95 lines (88 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import React from 'react';
import { Platform, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';
import * as Location from 'expo-location';
import * as Permissions from 'expo-permissions';
import Home from './components/Home';
import * as api from './api';
export default class App extends React.Component {
state = {
errorMessage: null,
actualRoute: [],
markers: [
{
id: 2,
latitude: 53.8008,
longitude: -1.5491
},
{
id: 5,
latitude: 53.8003,
longitude: -1.5491
},
{
id: 4,
latitude: 53.8006,
longitude: -1.5491
}
]
};
render() {
const { actualRoute, markers } = this.state;
return (
<View style={styles.container}>
<Home
actualRoute={actualRoute}
_watchPosition={this._watchPosition}
locationUpdates={this.location}
markers={markers}
/>
</View>
);
}
componentWillMount() {
if (Platform.OS === 'android' && !Constants.isDevice) {
this.setState({
errorMessage:
'Oops, this will not work on Sketch in an Android emulator. Try it on your device!'
});
} else {
this._getLocationAsync();
this._sendFlags();
}
}
_getLocationAsync = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
this.setState({
errorMessage: 'Permission to access location was denied'
});
}
};
_watchPosition = async () => {
this.locationUpdates = await Location.watchPositionAsync(
{ distanceInterval: 1 },
location => {
this.setState(currentState => {
const newLocation = {
latitude: location.coords.latitude,
longitude: location.coords.longitude
};
return {
actualRoute: [...currentState.actualRoute, newLocation]
};
});
}
);
};
_sendFlags = async () => {
const { flags } = await api.getFlags();
this.setState({ markers: flags });
};
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: Constants.statusBarHeight
}
});