@@ -32,18 +32,20 @@ export async function getWeather(items, position, lang) {
3232 }
3333 }
3434
35- http ( "GET" , `https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=${ pos . latitude } &lon=${ pos . longitude } ` , ( r ) => {
36- const weatherData = new WeatherData ( r . properties . timeseries [ 0 ] . data , lang || "en" )
35+ const weatherResponse = await http (
36+ "GET" ,
37+ `https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=${ pos . latitude } &lon=${ pos . longitude } `
38+ )
3739
38- document . getElementById ( "wicon" ) . src = `images/weather/ ${ weatherData . symbol_code } .png`
39- document . getElementById ( "wdescription " ) . innerText = weatherData . prettyName ( )
40- if ( items . temp_type === "fahrenheit" ) {
41- wtemp . innerText = ` ${ Math . round ( weatherData . temprature * ( 9 / 5 ) + 32 ) } °F`
42- } else {
43- wtemp . innerText = ` ${ Math . round ( weatherData . temprature ) } °C`
44- }
45- showWeatherContainer ( )
46- } )
40+ const weatherData = new WeatherData ( weatherResponse . properties . timeseries [ 0 ] . data , lang || "en" )
41+ document . getElementById ( "wicon " ) . src = `images/weather/ ${ weatherData . symbol_code } .png`
42+ document . getElementById ( "wdescription" ) . innerText = weatherData . prettyName ( )
43+ if ( items . temp_type === "fahrenheit" ) {
44+ wtemp . innerText = ` ${ Math . round ( weatherData . temprature * ( 9 / 5 ) + 32 ) } °F`
45+ } else {
46+ wtemp . innerText = ` ${ Math . round ( weatherData . temprature ) } °C`
47+ }
48+ showWeatherContainer ( )
4749
4850 // OpenStreetMap API can be rate limited, so we cache the location name for 1 hour
4951 const weatherLocation = await cache . get ( cacheKey )
@@ -55,13 +57,15 @@ export async function getWeather(items, position, lang) {
5557 return
5658 }
5759
58- reverseGeocode ( pos . latitude , pos . longitude , ( r ) => {
59- wname . innerText = (
60- r . address . city || r . address . town ||
61- r . address . village || r . address . hamlet ||
60+ const geoResponse = await reverseGeocode ( pos . latitude , pos . longitude )
61+
62+ wname . innerText = (
63+ geoResponse . address . city || geoResponse . address . town ||
64+ geoResponse . address . village || geoResponse . address . hamlet ||
6265 "Unknown Location"
63- )
64- showWeatherContainer ( )
65- cache . set ( cacheKey , wname . innerText )
66- } )
66+ )
67+ showWeatherContainer ( )
68+ cache . set ( cacheKey , wname . innerText )
69+
6770}
71+
0 commit comments