Will Scott

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](http://iconfactory.com/software/twitterrific) 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.

Requirements:

See the Full Script

Line one:

$status = simplexml_load_file(“http://twitter.com/statuses/user_timeline/[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 = “http://maps.google.com/staticmap?center=”.$loc.
“&zoom=15&size=300×250&format=jpg&key=[key]”;

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](http://gmaps-samples.googlecode.com/svn/trunk/simplewizard/makestaticmap.html) to let you configure your options.

Line four:

imagejpeg(imagecreatefromjpeg($map),”loc.jpg”);

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)

Exit mobile version