Getting the code to work
I then looked at first how I would get the key word to search. Using the ControlP5 library, I was able to create a text box and button that would then display whatever I had typed into the text box to the console. I took this and adapted it so it would set the text value as the value ‘question’. I also created a series of buttons with pre-defined key words that would always be on the page. Each of these buttons set the text box with a value as you can see here:
void happy(int theValue) {
myTextfield.setText(":)");
}
So by pressing enter when the text box is in focus, the first thing to happen is text in the text box is set to the value of ‘question’.
question = theEvent.controller().stringValue();
I then do a query based on the location of the city within ten miles and then by whatever the user is searching for. For example, I will show you how the search in London happens. Also the value I will be searching for in this demonstration will be the word ‘journey’.
int counter;
counter = 0;
GeoLocation location = new GeoLocation(51.500408,-0.125999);
Query location_query = new Query(question);
location_query = location_query.geoCode(location, (double)10.0, Query.MILES);
location_query.setRpp(100);
QueryResult result = myTwitter.search(location_query);
ArrayList tweets = (ArrayList) result.getTweets();
for (int i = 0; i < tweets.size(); i++) {
counter = counter + 1;
}
fill(counter*2, 255, 255);
stroke(0);
strokeWeight(2);
ellipse(lonx, lony, counter/2, counter/2);
counter = 0;
First of all, the application finds the geographical location I am trying to query. It then searches for any of those tweets containing ‘journey’ within ten miles of that location. It then limits that search to one hundred tweets. It then counts them using a loop and adding one to the value ‘counter’ for each tweet with ‘journey’ in and then sets the radius of its circle depending on how popular ‘journey’ was in that area, as well as changes the colour value of the circle to also reflect the same. The lighter and larger the circle, the more popular it is. It then resets the counter value for the next city.
The other locations are just the same, only with the initial coordinates changed and repeated for each of the eleven cities. I then added lines in between all of the cities for aesthetic effect.