Simple Embeddable Twitter Map Mashup
Earlier today, I was pondering the Digital Planet Listeners’ map on open2.net and the #digitalplanet Twitter feed we have running alongside it:
and I started to wonder whether there was a simple way of generating an embeddable map showing the location of people tweeting given a Twitter feed.
I couldn’t find one offhand, so here’s a simple pipe that will do the job: Simple Tweetmap pipe.
Here’s how it works: start off by grabbing a feed from Twitter, such as a Twitter search feed.
Using a Twitter feed URL as an input to the pipe, grab the feed and then find the Twitter username of each individual from the user’s Twitter URL. So for example, map http://twitter.com/psychemedia onto psychemedia.
We now call on another pipe that calls the Twitter API to get personal details for each user who has a Tweet in the feed.
Here’s how that embedded pipe works: Twitter location pipe (it should really be called “Twitter User Details” pipe).
First, construct a URI that ask the Twitter API for the user details associated a particular Twitter username, (e.g. using the construction http://twitter.com/users/show/USERNAME.json) then pull the data back as a JSON feed. Finally, just make sure only a single record is returned (there should only be one anyway).
So the embedded pipe passes back an annotation to the original feed with user details. One of the user details is the user’s location – so let’s geocode it:
Sending the output of the location finder to item.y:location allows the pipe to produce a well formed KML and geoRSS output, that can be displayed in a map, such as the Yahoo! Pipes output preview map:
We can grab the KML URL from the More Options output and display the feed in an embeddable Google map in the normal way (simply enter the KML URI in the Google maps search box and hit Search):
If you want to embed the map in your own page, just grab the embed code…
To summarise the hack, here’s a quick review of the whole pipe:
So now if you want to plot where people who have tagged their tweets in a particular way are tweeting from, you can do :-)
Next step is to persuade the open2 team to start archiving appropriately tagged tweets and displaying them on a cluster map view over time :-) We could maybe even link in a timeline using something like TimeMap, the MIT Simile timeline and Google Maps integration library…?