Edit (28th August 2011) This post is deprecated as Foursquare now requires Libraries/softs to use the OAuth protocol to authenticate users. The updated version of the code and how to install it explained in this post
One of the coolest feature of Google Lattitude is the widget that you can add to your blog or site to display your current location. Since I am already using Foursquare, I wanted to do the same by displaying my latest check-in. Turnout that foursquare provides an API to retrieve your latest check-in details, but I couldn’t find a code to create a widget from it. To fill this gap I wrote a small PHP class that fetches check-in data from Foursquare and generate a map for it by using Google map API. Using this class you can easily generate a widget that looks like the one below in less that 5 lines of code.

Since I might not be the only one to find this useful, I made the library available from here. Once you have it downloaded you can create your own widget by adding the following code :
/*
* Foursquare latest check-in widget example.
* Example of a webpage that display a widget that uses the foursquare.php class to
* connect to foursquare and retrive your last check-in details and the coresponding
* google map
* Author: Elie Bursztein (fourlocfetcher@elie.im)
* URL:
* License: GPL
*/
require_once 'foursquare.php'; //loading the class
$fq = new fourSquare("login", "pass"); //fetching the check-in data
?>
Last known location:
venueName?> (venueType?>)
"comment?>"
You should now have a fully functional widget
Note that the function $fq->getMapUrl() accepts many more arguments that let you customizes even further how the map look like. The full list of arguments is available in the google doc page and in the class directly.
If you think of features that you would like to see added or if you think I should do a WordPress plugin, then let me know. I will see what I can do
Pingback: Romania