hi,
How do I fetch and display the weather for several cities? Now that
I only get one city, I would like to show the weather from
different cities simultaneously. I can figure out how to loop the
results. Some suggestions?
function weatherBalloon( cityID ) {
var key = 'APIKEY';
fetch('https://api.openweathermap.org/data/2.5/weather?id='
+ cityID+ '&appid=' + key)
.then(function(resp) { return resp.json() }) // Convert data
to json
.then(function(data) {
drawWeather(data); //
Call drawWeather
})
.catch(function() {
// catch any errors
});
}
function drawWeather( d ) {
var celcius =
Math.round(parseFloat(d.main.temp)-273.15);
var fahrenheit =
Math.round(((parseFloat(d.main.temp)-273.15)*1.8)+32);
document.getElementById('description').innerHTML
= d.weather[0].description;
document.getElementById('temp').innerHTML =
celcius + '°';
document.getElementById('location').innerHTML =
d.name;
}
window.onload = function() {
weatherBalloon( 886842 );
}
hi, How do I fetch and display the weather for several cities? Now that I only get one city, I would like to show the we
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am