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…?

Author: Tony Hirst

I'm a lecturer at The Open University, with an interest in #opendata policy and practice, as well as general web tinkering...

13 thoughts on “Simple Embeddable Twitter Map Mashup”

  1. Hey, thanks for making this Pipe … it was exactly what I needed. In the minutes following an unusual small earth tremor in Melbourne, Australia, I decided to map the tweets to see if I could get an sense of how widespread it was. I cloned your Pipe (here: http://pipes.yahoo.com/pansapiens/earthquaketweets ) and used the twitter search http://search.twitter.com/search.atom?q=earthquake+OR+%23earthquake&rpp=100 to show as many recent tweets as I could with the term ‘earthquake’ or hashtag ‘#earthquake’.

    I can’t really say it gave me the answer I was looking for, probably because I was about 30 mins late, and by that time there were many people not in the directly effected area tweeting reactions, responding to Melbournians who tweeted about the tremor first hand. Unfortunately the Twitter search API doesn’t seem to have the option to restrict results by exact times (eg “between 8:55 and 9:00 pm”). It would be interesting to map the time-evolution of earthquake tweets over this period – I expect the immediate tweets in the first 2 – 5 mins would cover the directly effected areas, followed by reactions worldwide.

  2. Digging a little deeper, I’ve noticed that very few Twitterers set their location with exact lat/lon, but only provide a placename at the city level. This means the idea of mapping the effected area of things like earthquakes won’t work very well with any level of detail, since after reverse geocoding, the coodinates of most tweets aren’t really accurate enough to be useful. Maybe once more people start carrying GPS enabled smartphones to update their status (ala Android or iPhone), the data will get more interesting.

Comments are closed.