Repository navigation
Expand file tree
/
Copy pathApp.js
More file actions
143 lines (115 loc) · 3.6 KB
/
Copy pathApp.js
File metadata and controls
143 lines (115 loc) · 3.6 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
import { StyleSheet, Text, View, StatusBar, PermissionsAndroid, Platform,} from 'react-native';
import HomeScreen from './src/screens/HomeScreen/HomeScreen';
import DestinationSearch from './src/screens/DestinationSearch/DestinationSearch';
import SearchResults from './src/screens/SearchResults/SearchResults';
import { useEffect, useState } from 'react';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import * as React from 'react';
//import * as Location from 'expo-location';
import Geolocation, { getCurrentPosition } from 'react-native-geolocation-service';
navigator.geolocation = require('react-native-geolocation-service');
export default function App() {
const androidPermission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: "Uber App location Permission",
message:
"Uber App needs access to your location " +
"so you can take awesome rides.",
buttonNeutral: "Ask Me Later",
buttonNegative: "Cancel",
buttonPositive: "OK"
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("You can use the location");
} else {
console.log("Location permission denied");
}
} catch (err) {
console.warn(err);
}
};
useEffect(() => {
if (androidPermission) {
Geolocation.getCurrentPosition(
(position) => {
console.log(position);
},
(error) => {
// See error code charts below.
console.log(error.code, error.message);
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
);
}
}, [])
useEffect(() => {
if(Platform.OS == 'android') {
androidPermission()
} else{
//IOS
Geolocation.requestAuthorization();
}
}, [])
return (
<GestureHandlerRootView styles={{flex:1}}>
{/* <HomeScreen /> */}
<DestinationSearch />
{/* <SearchResults /> */}
</GestureHandlerRootView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
marginTop:StatusBar.currentHeight
},
});
// const [latLng, setLatLng] = useState({})
// const checkPermission = async() =>{
// const hasPermission = await Location.requestForegroundPermissionsAsync();
// if (hasPermission.status === 'granted') {
// const permission = await askPermission();
// return permission
// }
// return true
// };
// const askPermission = async()=>{
// const permission = await Location.requestForegroundPermissionsAsync()
// return permission.status === 'granted';
// };
// const getLocation = async()=>{
// try {
// const {granted} = await Location.requestForegroundPermissionsAsync();
// if (!granted)return;
// const {
// coords:{latitude,longitude},
// } = await Location.getCurrentPositionAsync();
// setLatLng({latitude:latitude, longitude:longitude})
// } catch(err){
// }
// };
// useEffect(() => {
// checkPermission();
// getLocation()
// }, [])
// useEffect(() => {
// if (getLocation) {
// Geolocation.getCurrentPosition(
// (position) => {
// console.log(position);
// },
// (error) => {
// // See error code charts below.
// console.log(error.code, error.message);
// },
// { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
// );
// }
// }, [])