Potential fix to expo-location crash

This commit is contained in:
Keannu Bernasol 2023-07-19 17:57:25 +08:00
parent 334978d2fd
commit 98bd8dcfb8

View file

@ -23,22 +23,23 @@ export default function Home() {
latitudeDelta: 0.000235, latitudeDelta: 0.000235,
longitudeDelta: 0.000067, longitudeDelta: 0.000067,
}; };
async function requestLocation() { async function requestLocation() {
let { status } = await Location.requestForegroundPermissionsAsync(); setTimeout(async () => {
if (status !== "granted") { const { status } = await Location.requestForegroundPermissionsAsync();
setFeedback( if (status !== "granted") {
"Permission to access location was denied. Please allow permission" setFeedback(
); "Permission to access location was denied. Please allow permission"
return; );
} return;
if (status == "granted") {
let location = await Location.getCurrentPositionAsync({});
if (location) {
setLocation(location);
getDistance(location);
} }
} if (status == "granted") {
let location = await Location.getCurrentPositionAsync({});
if (location) {
setLocation(location);
getDistance(location);
}
}
}, 2000);
} }
useEffect(() => { useEffect(() => {
requestLocation(); requestLocation();