-
Notifications
You must be signed in to change notification settings - Fork 0
/
locationSlice.js
81 lines (59 loc) · 1.93 KB
/
locationSlice.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
import React from "react";
import { View, Text } from "react-native";
import MapView, { PROVIDER_GOOGLE } from 'react-native-maps';
import * as Location from 'expo-location';
import CustomMarker from "./customMarker";
import locationStoreSlice from "./locationStoreSlice";
export default function LocationSlice() {
const handleNavigateHome = () => {
navigation.navigate('Home');
};
const [selectedPlaceId, setSelectedPlaceId] = React.useState();
const [mylocation, setMyLocation] = React.useState();
const currentLocationId = 'currentLocation';
React.useEffect(() => {
const getPermissions = async () => {
let { status } = await Location.requestForegroundPermissionsAsync();
if (status !== 'granted') {
console.log('grant location permission')
return;
}
let currentLocation = await Location.getCurrentPositionAsync({});
setMyLocation(currentLocation);
console.log('Location:');
console.log(currentLocation);
};
getPermissions();
}, []);
return (
<View style={{ width: '100%', height: '100%' }}>
<MapView style={{ width: '100%', height: '100%' }}
provider={PROVIDER_GOOGLE}
initialRegion={{
latitude: 45.406820714352705,
longitude: 11.879521989852064,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
>
{locationStoreSlice.map(location =>
<CustomMarker
isSelected={location.id === selectedPlaceId}
onPress={() => {
setSelectedPlaceId(location.id)
}}
coordinate={location.coordinate}
/>)}
{mylocation &&
<CustomMarker
isSelected={currentLocationId === selectedPlaceId}
onPress={() => {
setSelectedPlaceId(currentLocationId)
}}
coordinate={mylocation.coords}
/>
}
</MapView>
</View>
);
}