I figured out a simple way to make a mashup that displays tweets from twitter on a Google Map. Click on the pin and a window pops up containing the last tweet that was updated. It is easy to change the location of the pin or the twitter feed that is addressed to obtain the latest tweet. For your reference, here's a pretty print of the code using Google Code Javascript code prettifier:
Here is how it works:
Twitter API rocks with a JSON feed for every user. Adding a callback function makes it very convient to read the data. Just call a JSON object http://www.twitter.com/statuses/user_timeline/user
http://www.twitter.com/statuses/user_timeline/user.json?callback=twitterCallback&count=1
Replace user with your Twitter nickname. In my case, it's cast42.The count parameter is set to 1 such that only the most recent tweet is obtained.
var tweet = new Object;
function twitterCallback(obj) {
tweet.text = obj[0].text;
}
The full source code can be downloaded from the example. Don't forget to fill in your own Google Maps key and replace cast42 with your own twitter name.
No comments:
Post a Comment