-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
119 lines (103 loc) · 2.87 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import React, { useState, useEffect } from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
PermissionsAndroid,
Alert,
Button,
BackHandler,
Dimensions
} from 'react-native';
import Map from './components/mapa'
import MapView, {Marker} from 'react-native-maps';
import Geolocation from '@react-native-community/geolocation'
import Icon from 'react-native-vector-icons/FontAwesome';
import socketIOClient from 'socket.io-client'
endPoint = 'http://192.168.1.14:3001'
const io = socketIOClient(endPoint)
function App(){
const [locationEnabled, setLocationEnabled] = useState(false)
const [watchID, setWatchID] = useState(null)
const [location, setLocation] = useState(null)
useEffect(
() =>{
PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION).then(
response => {
if (response) {
console.log("Permitido")
setLocationEnabled(true)
}else{
console.log("Sem permissaso ate aqui")
getLocationPermission()
}
}
)
io.on('teste', ()=>{
console.log('teste')
})
}, []
)
const startWatch = () => {
const myWatchId = Geolocation.watchPosition((location)=>{
setLocation({
latitude: location.coords.latitude,
longitude: location.coords.longitude
})
}, (err)=>{
console.log(err)
}, {
enableHighAccuracy: true,
distanceFilter: 1,
maximumAge: 0,
});
setWatchID(myWatchId)
}
const stopWatch = () => {
Geolocation.clearWatch(watchID)
Geolocation.stopObserving();
setLocation(null)
}
const getLocationPermission = async () => {
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
setLocationEnabled(true)
} else {
Alert.alert(
'Para usar o aplicativo, precisamos da sua localizacao',
'Por favor ative nas configs do seu celualar',
[
{text: 'Ok, entendi', onPress: ()=>{BackHandler.exitApp()}}
]
)
}
}
return (
<View>
<View style = {{display: 'flex', flexDirection: 'row', justifyContent: 'center', alignItems: 'center'}} >
<View style={{minWidth: 150, margin: 10}}>
<Button title="Ativar" onPress={startWatch} />
</View>
<View style={{minWidth: 150, margin: 10}}>
<Button title="Desativar" onPress={stopWatch} />
</View>
</View>
<View style={styles.map} >
<Map styles={styles} location={location} Icon={Icon} ></Map>
</View>
</View>
);
};
const styles = StyleSheet.create({
map:{
width: Dimensions.get('window').width,
height: Dimensions.get('window').height
},
mapBox: {
flex:1
},
});
export default App;