xxxxxxxxxx
var baseurl = 'https://api.openweathermap.org/data/2.5/weather';
var appid = '7bbbb47522848e8b9c26ba35c226c734';
var units = 'imperial';
var weather = {};
var inputfield, button;
var isLoaded = false;
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
stroke(0);
fill(0);
textSize(25);
inputfield = createInput('Honolulu, Hawaii, USA');
inputfield.position(40, 150);
button = createButton('click me');
button.position(40,180);
button.mousePressed(clickme); // what function runs when I click the button
asktheweather(inputfield.value());
}
function draw() {
background(100);
if(isLoaded) {
text(weather.name, 40, 40);
text(weather.coord.lat + ' by ' + weather.coord.lon, 40, 60);
text(weather.main.temp + ' F', 40, 80);
}
}
function clickme()
{
var v = inputfield.value();
asktheweather(v);
}
function asktheweather(c) // request function
{
var URL = baseurl+'?q='+c+'&units='+units+'&appid='+appid;
isLoaded = false;
weather = loadJSON(URL, gotit);
}
function gotit() { // response function
isLoaded = true;
}