I am trying to map geolocations (and other features) from live JSON feed, but the plotted locations are not displaying accurately i.e. they do not align with the Unfolding map base. I am trying to use getScreenPosition (second last line of the code) to fix this, but am getting "event.location cannot be solved or is not a field" message. I am a complete beginner at this, so probably missing something that is obvious to someone else. Can anyone tell me what I am doing wrong here? Thanks in advance! Here's the full code:
UnfoldingMap map;
void setup() {
size(800, 600);
map = new UnfoldingMap(this);
map.zoomAndPanTo(new Location(41.9f, -87.7f), 10);
MapUtils.createDefaultEventDispatcher(this, map);
}
JSONArray events;
String url = "http:" + "//divvybikes.com/stations/json";
float minLat = 41.77;
float maxLat = 41.99;
float minLon = -87.75;
float maxLon = -87.55;
void draw()
{
if(frameCount%30==0 || frameCount==1)
{
getLatest();
}
drawLatest();
}
void getLatest()
{
JSONObject rawEvents = loadJSONObject(url);
events = rawEvents.getJSONArray("stationBeanList");
}
void drawLatest()
{
fill(255,0,0);
map.draw();
for(int i =0; i<events.size(); i++)
{
JSONObject event = events.getJSONObject(i);
float x = map(event.getFloat("longitude"), minLon, maxLon, 0, width);
float y = map(event.getFloat("latitude"), minLat, maxLat, height, 0);
float n = event.getFloat("availableBikes");
Location location = new Location(x, y);
ScreenPosition pos = map.getScreenPosition(event.location);
ellipse(pos.x, pos.y, n, n);
}
}