refactor: restructure geolocation handling for improved readability

This commit is contained in:
wont-stream 2025-04-10 10:45:03 -04:00
parent be2b3d09dc
commit 8de0faf8fa

View file

@ -37,11 +37,24 @@ export default () => {
setWttrDesc(`${weatherDesc.description} & ${dayOrNight}`);
}
(async () => {
const getAproximateLocation = async () => {
const req = await fetch("https://cf.ipv4-army.workers.dev/")
const res = await req.json();
return await getWeather(res);
})()
}
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition((position) => {
const coords = position.coords;
getWeather(coords);
}, getAproximateLocation, {
enableHighAccuracy: true,
maximumAge: 30 * 60 * 1000, // 30 minutes
timeout: 5000
});
} else {
getAproximateLocation();
}
return (
<>