-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
103 lines (100 loc) · 3.18 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import MapView, { PROVIDER_GOOGLE } from 'react-native-maps';
const platform = Platform.select({
ios: () => 'ios',
android: () => 'android',
})();
type Props = {};
export default class App extends Component<Props> {
constructor(props) {
super(props);
this.map = null;
this.state = {
mapOption: {
enableHighAccuracy: false,
timeout: 5000,
maximumAge: 0
},
initialRegion: {
latitude: 13.781058,
longitude: 100.4914531,
latitudeDelta: 0.0922 / 10,
longitudeDelta: 0.0421 / 10,
},
initialMarker: {
locationName: 'Last Location',
latitude: 13.781058,
longitude: 100.4914531,
latitudeDelta: 0.0922 / 10,
longitudeDelta: 0.0421 / 10,
},
};
}
// ตำแหน่งปัจจุบัน
onRegionChange(regionCurrent) {
console.log(regionCurrent);
}
// ตำแหน่งปัจจุบัน
onRegionChangeComplete(regionCurrent) {
console.log(regionCurrent);
}
render() {
if (platform === 'ios') {
return (
<View style={styles.container}>
<MapView
ref={(map) => { this.map = map; }}
style={styles.map}
showsUserLocation={true}
followsUserLocation={true}
moveOnMarkerPress={false}
zoomEnabled={false}
scrollEnabled={false}
initialRegion={this.state.initialRegion}
region={this.state.initialRegion}
onRegionChange={(region) => this.onRegionChange(region)}
onRegionChangeComplete={(region) => this.onRegionChangeComplete(region)}>
</MapView>
<MapView.Circle center={{ latitude : this.state.initialMarker.latitude, longitude : this.state.initialMarker.longitude }} radius={200} strokeColor="rgba(197, 0, 48, 0.9)" fillColor="rgba(197, 50, 81, 0.9)"></MapView.Circle>
</View>
);
}
if (platform === 'android') {
return (
<View style={styles.container}>
<MapView
ref={(map) => { this.map = map; }}
style={styles.map}
provider={PROVIDER_GOOGLE}
showsUserLocation={true}
followsUserLocation={true}
moveOnMarkerPress={false}
zoomEnabled={false}
scrollEnabled={false}
initialRegion={this.state.initialRegion}
region={this.state.initialRegion}
onRegionChange={(region) => this.onRegionChange(region)}
onRegionChangeComplete={(region) => this.onRegionChangeComplete(region)}>
<MapView.Marker coordinate={{ latitude : this.state.initialMarker.latitude, longitude : this.state.initialMarker.longitude }} title={this.state.initialMarker.locationName}/>
</MapView>
</View>
);
}
return null;
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'flex-end',
},
map: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
},
});