Skip to content

Commit

Permalink
Merge pull request #399 from nickthegroot/nickdegroot/fix-wrong-city-…
Browse files Browse the repository at this point in the history
…temp

Weather Widget: Fix Location Lookup
  • Loading branch information
Jean-Tinland authored May 20, 2024
2 parents a002288 + 62497a0 commit c3a63f9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/components/data/weather.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c3a63f9

Please sign in to comment.