Add My Location in 4 Lines

I’ve started using twitter as a very easy way to update this site, and since it integrates well with my iPhone I wanted to show off another cool feature. [Twitterific]( Provides a feature to change your twitter location to that of your iphone. From this base, it becomes very easy to add a map showing your location.


  • iPhone with twitterific
  • Twitter Account
  • Google Maps API Key ([free here](

See the Full Script

Line one:

$status = simplexml_load_file(“[userid].xml”);

where [userid] is your twitter userid.
This Line downloads and parses your recent tweets. The xml format serialized by twitter also includes your current location

Line two:

$loc = str_replace(“iPhone: “,””,$status->status[0]->user->location);

This line extracts the location coordinates from the twitter response.

Line three:

$map = “”.$loc.

where [key] is your google maps api key.
This is where you can fiddle around with the map to display. Google has an interactive [wizard]( to let you configure your options.

Line four:


this line saves the map locally, so you can serve it from your own server and keep it cached. Additionally you can add overlays or manipulate the image before saving.

Some examples of what’s possible:

![Example 1](/twitterloc/example1.gif)
![Example 2](/twitterloc/example2.gif)

Categorized as Post