refactor: restructure geolocation handling for improved readability
This commit is contained in:
parent
be2b3d09dc
commit
8de0faf8fa
1 changed files with 15 additions and 2 deletions
|
@ -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 (
|
||||
<>
|
||||
|
|
Loading…
Add table
Reference in a new issue