-
Notifications
You must be signed in to change notification settings - Fork 11
/
App.js
71 lines (65 loc) · 1.75 KB
/
App.js
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
import React from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import { MapView, Constants, Location, Permissions } from 'expo';
export default class App extends React.Component {
state = {
location: null,
errorMessage: null,
};
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();
}
}
_getLocationAsync = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
this.setState({
errorMessage: 'Permission to access location was denied',
});
}
let location = await Location.getCurrentPositionAsync({});
this.setState({ location });
};
render() {
if (this.state.location == null) {
return (<View style={styles.container}/>);
}
else
{
return (
<MapView
style={{ flex: 1 }}
provider={'google'}
region={{
latitude: this.state.location.coords.latitude,
longitude: this.state.location.coords.longitude,
latitudeDelta: 0,//0.0922,
longitudeDelta: 0.01//0.0421,
}}
>
<MapView.Circle
radius={20}
fillColor={'#00F'}
center={{
latitude: this.state.location.coords.latitude,
longitude: this.state.location.coords.longitude
}}
/>
</MapView>
);
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});