Possible fix to gps crash

This commit is contained in:
Keannu Bernasol 2023-07-19 22:21:19 +08:00
parent 98bd8dcfb8
commit 60f2250cb8

View file

@ -4,7 +4,7 @@ import { useSelector } from "react-redux";
import { RootState } from "../../features/redux/Store/Store"; import { RootState } from "../../features/redux/Store/Store";
import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer"; import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer";
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import MapView, { Marker, UrlTile } from "react-native-maps"; import MapView, { Animated as AnimatedMap } from "react-native-maps";
import * as Location from "expo-location"; import * as Location from "expo-location";
import GetDistance from "../../components/GetDistance/GetDistance"; import GetDistance from "../../components/GetDistance/GetDistance";
import Button from "../../components/Button/Button"; import Button from "../../components/Button/Button";
@ -33,17 +33,25 @@ export default function Home() {
return; return;
} }
if (status == "granted") { if (status == "granted") {
let location = await Location.getCurrentPositionAsync({}); try {
if (location) { let location = await Location.getCurrentPositionAsync({});
setLocation(location); if (location) {
getDistance(location); setLocation(location);
getDistance(location);
}
} catch (error) {
setFeedback("Error: " + error);
} }
} }
}, 2000); }, 2000);
} }
useEffect(() => { useEffect(() => {
requestLocation(); const interval = setInterval(() => {
}, [location]); requestLocation();
}, 1000);
return () => clearInterval(interval);
});
useEffect(() => { useEffect(() => {
requestLocation(); requestLocation();
}, []); }, []);
@ -81,7 +89,7 @@ export default function Home() {
You are too far from USTP {"\n"} You are too far from USTP {"\n"}
Get closer to use Stud-E Get closer to use Stud-E
</Text> </Text>
<MapView <AnimatedMap
style={{ style={{
height: Viewport.height * 0.5, height: Viewport.height * 0.5,
width: Viewport.width * 0.8, width: Viewport.width * 0.8,