xxxxxxxxxx
45
let weather;
let url = "https://api.openweathermap.org/data/2.5/weather?q=";
let city;
let unit = "&units=imperial";
let appid = "&appid=c4f15c1a3591cfdddd1020a6b2c1caec";
let input
function setup() {
createCanvas(500,500)
input = createInput();
input.position(20, 125);
button = createButton('submit');
button.position(input.x + input.width,125);
button.mousePressed(jLoad);
}
function draw() {
background(255);
// console.log(weather);
if (weather) {
text(weather.main.temp + " degrees", 20, 20);
text(weather.weather[0].description, 20, 40);
text(weather.visibility, 20, 60);
text(weather.wind.speed, 20, 80);
text(weather.name, 20, 100);
}
}
function jLoad() {
city = input.value()
//New%20York,us
loadJSON(url + city + unit + appid, done);
console.log(city)
input.value("")
}
function done(data) {
weather = data;
}