Wednesday, July 22, 2009

Location data on your.flowingdata

Yesterday I posted about how I am using your.flowingdata to track my email statistics. Today, I will go into the details of how I am tracking my location using Google Latitude and YFD.

The first step was to enable Google Latitude on my BlackBerry, which I did quite some time ago. Latitude is an option in the mobile version of Google Maps that reports your location back to Google, and tells you the location of other members of your social network. A Google search told me that there is an API that lets you access this location information in KML or JSON format. I decided to use the JSON version, since Python has a couple of different JSON libraries. I picked simplejson.

So, what I wanted was to tell YFD where I am, at least as far as Latitude knows. Here's how I did it:


import twitter, simplejson, urllib

# set some options
options = {}
options['twitteruser'] = 'my Twitter username'
options['twitterpass'] = 'my Twitter password'
options['latitudeid'] = 'my Google Latitude ID'

# in case you don't want to hard code your password in the script
if options['twitterpass'] == None or options['twitterpass'] == '':
options['twitterpass'] = getpass.getpass('Twitter password:')

# get your location from Google Latitude
url = '' +
result = simplejson.load(urllib.urlopen(url))
coordinates = result['features'][0]['geometry']['coordinates']
lon = coordinates[0]
lat = coordinates[1]
location = result['features'][0]['properties']['reverseGeocode']

# connect to twitter and post a message to @yfd
api = twitter.Api(options['twitteruser'],options['twitterpass'])
status = api.PostDirectMessage('yfd','location %f,%f (%s)' % (lon, lat, location))
A nice optimization I should add would be to cache the location and only tweet it if it has changed.

Shortly after I tweeted about this script, Nathan tweeted back the following:
@niel great! working location i.e. maps into YFD is in the works

So hopefully I will be able to generate maps from my data natively in YFD. In the meantime, of course, there are ways to access the data and mash it up with Google Maps myself.

Next: telephone data via Google Voice, and, if possible, Vonage. (Getting an API to access AT&T Wireless call data seems very unlikely.)

No comments: