Repository navigation
Expand file tree
/
Copy pathApp.js
More file actions
151 lines (145 loc) · 3.79 KB
/
Copy pathApp.js
File metadata and controls
151 lines (145 loc) · 3.79 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import React, {useState} from 'react';
import {
PermissionsAndroid,
Alert,
View,
Text,
TouchableOpacity,
StyleSheet,
} from 'react-native';
import MapView, {Marker} from 'react-native-maps';
import Geolocation from 'react-native-geolocation-service';
import Icon from 'react-native-vector-icons/MaterialIcons';
const App = () => {
const [position, setPosition] = useState({
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
});
const request_location_runtime_permission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: 'Permissão de Localização',
message: 'A aplicação precisa da permissão de localização.',
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
Geolocation.getCurrentPosition(
pos => {
setPosition({
...position,
latitude: pos.coords.latitude,
longitude: pos.coords.longitude,
});
},
error => {
console.log(error);
Alert.alert('Houve um erro ao pegar a latitude e longitude.');
},
);
} else {
Alert.alert('Permissão de localização não concedida');
}
} catch (err) {
console.log(err);
}
};
return (
<View style={styles.container}>
<MapView
style={styles.map}
region={position}
onPress={e =>
setPosition({
...position,
latitude: e.nativeEvent.coordinate.latitude,
longitude: e.nativeEvent.coordinate.longitude,
})
}>
<Marker
coordinate={position}
title={'Marcador'}
description={'Testando o marcador no mapa'}
/>
</MapView>
<View style={styles.positonBox}>
<Text style={styles.positonBoxTitle}>Sua Localização</Text>
<View style={styles.positonBoxLatLon}>
<Text style={{fontSize: 18}}>Lat.</Text>
<Text style={{fontSize: 18}}>{position.latitude}</Text>
</View>
<View style={styles.positonBoxLatLon}>
<Text style={{fontSize: 18}}>Lon.</Text>
<Text style={{fontSize: 18}}>{position.longitude}</Text>
</View>
</View>
<TouchableOpacity
style={styles.locationButton}
onPress={() => {
request_location_runtime_permission();
}}>
<Icon name="my-location" color={'#fff'} size={30} />
</TouchableOpacity>
<View style={styles.logo}>
<Text style={styles.logoText}>Samurai</Text>
<Text style={[styles.logoText, {color: '#e74c3c'}]}>Map</Text>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
map: {
height: '100%',
width: '100%',
},
logo: {
backgroundColor: '#fff',
borderRadius: 15,
paddingHorizontal: 15,
elevation: 5,
marginTop: -730,
alignSelf: 'center',
marginRight: 10,
flexDirection: 'row',
},
logoText: {
fontWeight: 'bold',
fontSize: 22,
},
positonBox: {
backgroundColor: '#fff',
borderRadius: 20,
opacity: 0.75,
marginTop: -170,
marginHorizontal: 40,
padding: 25,
shadowColor: '#000',
elevation: 5,
},
positonBoxTitle: {
textAlign: 'center',
fontSize: 22,
fontWeight: 'bold',
color: '#e74c3c',
},
positonBoxLatLon: {flexDirection: 'row', justifyContent: 'space-between'},
locationButton: {
backgroundColor: '#e74c3c',
borderRadius: 150,
marginTop: -25,
width: 50,
height: 50,
alignSelf: 'center',
justifyContent: 'center',
alignItems: 'center',
shadowColor: '#000',
elevation: 8,
},
});
export default App;