Switch to open street view to hopefully fix production crashes with gps

This commit is contained in:
Keannu Bernasol 2023-07-20 18:31:51 +08:00
parent 60f2250cb8
commit 17b41cde65

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, { Animated as AnimatedMap } from "react-native-maps"; import MapView, { Animated as AnimatedMap, UrlTile } 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";
@ -24,7 +24,6 @@ export default function Home() {
longitudeDelta: 0.000067, longitudeDelta: 0.000067,
}; };
async function requestLocation() { async function requestLocation() {
setTimeout(async () => {
const { status } = await Location.requestForegroundPermissionsAsync(); const { status } = await Location.requestForegroundPermissionsAsync();
if (status !== "granted") { if (status !== "granted") {
setFeedback( setFeedback(
@ -33,18 +32,13 @@ export default function Home() {
return; return;
} }
if (status == "granted") { if (status == "granted") {
try {
let location = await Location.getCurrentPositionAsync({}); let location = await Location.getCurrentPositionAsync({});
if (location) { if (location) {
setLocation(location); setLocation(location);
getDistance(location); getDistance(location);
} }
} catch (error) {
setFeedback("Error: " + error);
} }
} }
}, 2000);
}
useEffect(() => { useEffect(() => {
const interval = setInterval(() => { const interval = setInterval(() => {
requestLocation(); requestLocation();
@ -80,7 +74,14 @@ export default function Home() {
rotateEnabled={false} rotateEnabled={false}
followsUserLocation={true} followsUserLocation={true}
minZoomLevel={15} minZoomLevel={15}
>
<UrlTile
urlTemplate="https://c.tile.openstreetmap.org/${z}/${x}/${y}.png"
shouldReplaceMapContent={true}
maximumZ={19}
flipY={false}
/> />
</MapView>
); );
} else { } else {
return ( return (
@ -89,7 +90,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>
<AnimatedMap <MapView
style={{ style={{
height: Viewport.height * 0.5, height: Viewport.height * 0.5,
width: Viewport.width * 0.8, width: Viewport.width * 0.8,
@ -107,7 +108,14 @@ export default function Home() {
latitudeDelta: 0.0922, latitudeDelta: 0.0922,
longitudeDelta: 0.0421, longitudeDelta: 0.0421,
}} }}
>
<UrlTile
urlTemplate="https://c.tile.openstreetmap.org/${z}/${x}/${y}.png"
shouldReplaceMapContent={true}
maximumZ={19}
flipY={false}
/> />
</MapView>
<Text style={styles.text_white_small}> <Text style={styles.text_white_small}>
{dist}km away from USTP {"\n"} {dist}km away from USTP {"\n"}
</Text> </Text>