Cast for two

Wednesday, July 04, 2007

Twitter tweets on Goople maps mashup

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:

alt : test.html

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 and add a callbackfunction. In our case, the function is called "twitterCallback". The full URL becomes:
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. In the callback function it's easy to obtain the text from the latest tweet:
   var tweet = new Object;
function twitterCallback(obj) {
.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: