xxxxxxxxxx
var NUMRECORDS = 100; // how many records
var NYCAPIURL = 'https://data.cityofnewyork.us/resource/43nn-pn8j.json'; // restaurant inspection database
var GEOCODEURL = 'https://www.mapquestapi.com/geocoding/v1/batch?key=rDz5dqQpjbkQxzs1ktmvT3qcaw0QTxNf&inFormat=kvp&outFormat=json&thumbMaps=false';
var thestuff = {};
var locationdata = {};
var isready = false;
var fontsize = 18;
function preload() {
thestuff = loadJSON(NYCAPIURL, goforit);
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
stroke(0);
fill(0);
textSize(fontsize);
}
function draw() {
if(isready)
{
background(0);
fill(255);
let y = fontsize;
for(let i =0;i<NUMRECORDS;i++)
{
fill(255);
let s = '';
s+=thestuff[i].dba + ' : ';
s+=thestuff[i].cuisine_description + ', ';
s+=thestuff[i].violation_description + '!!!';
text(s, 20, y);
y+=fontsize;
fill(255, 0, 0);
let a = thestuff[i].building + ' ' + thestuff[i].street + ' ' + thestuff[i].boro + ' ' + thestuff[i].zipcode + ' ' + thestuff[i].lat + ' x ' + thestuff[i].lng;
text(a, 40, y);
y+=fontsize;
}
}
}
function goforit() { // response function
dogeocode();
}
function dogeocode() {
for(let i =0;i<NUMRECORDS;i++)
{
let a = thestuff[i].building + ' ' + thestuff[i].street + ' ' + thestuff[i].boro + ' ' + thestuff[i].zipcode;
GEOCODEURL+='&location='+a;
}
locationdata = loadJSON(GEOCODEURL, geocoded);
}
function geocoded()
{
for(let i = 0;i<NUMRECORDS;i++)
{
thestuff[i].lat = locationdata.results[i].locations[0].latLng.lat;
thestuff[i].lng = locationdata.results[i].locations[0].latLng.lng;
}
isready = true;
}