From 62497a0c56671ceb551589b3affd38a391c6cd13 Mon Sep 17 00:00:00 2001 From: Nick DeGroot <1966472+nickthegroot@users.noreply.github.com> Date: Thu, 9 May 2024 15:48:27 -0700 Subject: [PATCH] :bug: Fetch weather location by coordinates instead of city --- lib/components/data/weather.jsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/components/data/weather.jsx b/lib/components/data/weather.jsx index 7a217e5e..c604616e 100644 --- a/lib/components/data/weather.jsx +++ b/lib/components/data/weather.jsx @@ -51,7 +51,15 @@ export const Widget = React.memo(() => { if (!location.current) { const position = await Promise.race([getPosition(), Utils.timeout(5000)]); if (!position) await getWeather(); - location.current = position?.address?.city; + + const coordinates = position?.position?.coords; + if (!coordinates) return setLoading(false); + + const accuracy = 10 ** 2; // 2 decimal places + const latitute = Math.round(coordinates.latitude * accuracy) / accuracy; + const longitude = Math.round(coordinates.longitude * accuracy) / accuracy; + + location.current = `${latitute},${longitude}`; if (!location.current) return setLoading(false); } try {