File tree Expand file tree Collapse file tree 2 files changed +20
-9
lines changed Expand file tree Collapse file tree 2 files changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -8,9 +8,15 @@ import Main from './src/Main';
8
8
9
9
const App = ( ) => {
10
10
React . useEffect ( ( ) => {
11
- ( async ( ) => {
12
- await Location . requestForegroundPermissionsAsync ( ) ;
13
- } ) ( ) ;
11
+ const getLocationPermission = async ( ) => {
12
+ try {
13
+ await Location . requestForegroundPermissionsAsync ( ) ;
14
+ } catch ( e ) {
15
+ console . log ( 'requestForegroundPermissionsAsync failed' ) ;
16
+ }
17
+ } ;
18
+
19
+ setTimeout ( getLocationPermission , 1000 ) ;
14
20
} , [ ] ) ;
15
21
16
22
return (
Original file line number Diff line number Diff line change @@ -47,11 +47,13 @@ const Map = () => {
47
47
48
48
const getCurrentUserLocation = ( ) => {
49
49
( async ( ) => {
50
- const location = await Location . getCurrentPositionAsync ( ) ;
51
- dispatcher ?. setUserLocation ( location ) ;
52
- } ) ( ) . catch ( ( ) => {
53
- console . log ( 'No location permissions granted.' ) ;
54
- } ) ;
50
+ try {
51
+ const location = await Location . getCurrentPositionAsync ( ) ;
52
+ dispatcher ?. setUserLocation ( location ) ;
53
+ } catch ( e ) {
54
+ console . log ( 'No location permissions granted.' ) ;
55
+ }
56
+ } ) ( ) ;
55
57
} ;
56
58
57
59
const moveMapToUser = ( ) => {
@@ -70,9 +72,12 @@ const Map = () => {
70
72
} ;
71
73
72
74
React . useEffect ( updateVehiclesOnForeground , [ route ] ) ;
73
- React . useEffect ( getCurrentUserLocation , [ ] ) ;
74
75
React . useEffect ( moveMapToUser , [ location ] ) ;
75
76
77
+ // get current user location on load and if dispatcher changes
78
+ React . useEffect ( getCurrentUserLocation , [ ] ) ;
79
+ React . useEffect ( getCurrentUserLocation , [ dispatcher ] ) ;
80
+
76
81
return (
77
82
< View style = { { width, height } } >
78
83
< MapView
You can’t perform that action at this time.
0 commit comments