Hello! I was able to load one JSON url from Yahoo Weather, but now I am having trouble loading multiple urls. I tried searching my question on stack overflow, but the posts I found mentioned one JSON url, not several. Also, I tried applying Daniel Shiffman’s tutorial to multiple urls, but I am still doing something wrong in the code. First, I had my loadJSON commands in preload, not setup, which I thought was the problem. Another problem might be how I define and use dataAll, which is a variable that includes all my data sets. How can I load multiple JSON urls correctly? Here is the relevant code:
var balls = []; // array of Jitter objects
var dataChicago;
var dataAurora;
var dataJoliet;
var dataNaperville;
var dataRockford;
var dataSpringfield;
var dataElgin;
var dataPeoria;
var dataAll = dataChicago, dataAurora, dataJoliet, dataNaperville, dataRockford, dataSpringfield, dataElgin, dataPeoria;
var dates = []; // an array of all the "date" values
var texts = []; // an array of all the "text" values
var temps = []; // an array of all the "high" values
var chicagoData;
var auroraData;
var jolietData;
var napervilleData;
var rockfordData;
var springfieldData;
var elginData;
var peoriaData;
var allData = chicagoData, auroraData, jolietData, napervilleData, rockfordData, springfieldData, elginData, peoriaData;
function setup() {
createCanvas(windowWidth, windowHeight);
var urlchicago = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22chicago%2C%20il%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
var urlaurora = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22aurora%2C%20il%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
var urljoliet = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22joliet%2C%20il%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
var urlnaperville = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22naperville%2C%20il%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
var urlrockford = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22rockford%2C%20il%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
var urlspringfield = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22springfield%2C%20il%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
var urlelgin = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22elgin%2C%20il%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
var urlpeoria = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22peoria%2C%20il%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
loadJSON(urlchicago, gotData, 'jsonp');
loadJSON(urlaurora, gotData, 'jsonp');
loadJSON(urljoliet, gotData, 'jsonp');
loadJSON(urlnaperville, gotData, 'jsonp');
loadJSON(urlrockford, gotData, 'jsonp');
loadJSON(urlspringfield, gotData, 'jsonp');
loadJSON(urlelgin, gotData, 'jsonp');
loadJSON(urlpeoria, gotData, 'jsonp');
noStroke();
for (var i=0; i<10; i++) {
balls.push(new Hello());
}
}
function gotData(dataChicago) {
chicagoData = dataChicago;
//console.log(data);
}
function gotData(dataAurora) {
auroraData = dataAurora;
}
function gotData(dataJoliet) {
jolietData = dataJoliet;
}
function gotData(dataNaperville) {
napervilleData = dataNaperville;
}
function gotData(dataRockford) {
rockfordData = dataRockford;
}
function gotData(dataSpringfield) {
springfieldData = dataSpringfield;
}
function gotData(dataElgin) {
elginData = dataElgin;
}
function gotData(dataPeoria) {
peoriaData = dataPeoria;
}
function gotData(dataAll) {
allData = dataAll;
}
function draw() {
background(66, 223, 244, 230);
if (allData) {
var allData = dataAll.query.results.channel.item.forecast;
for (var i=0; i<allData.length; i++) {
dates[i] = allData[i].date;
texts[i] = allData[i].text;
temps[i] = allData[i].high;
balls[i].move(temps[i]);
balls[i].display(temps[i], dates[i]);
}
}
}
Thanks in advance!