Google latitude is a great way to share your current GPS location with everyone. You can put up the google location badge on your blog and let the world know your exact geographical location.
But the latitude badge does not provide the exact address of your current location in terms of the area names but shows the exact location on the map. Google latitude badge shows only city level address along with the map. So I decided to write my own small PHP script to print out the exact address instead of an approximate one which is shown by default. You could use this code coupled with XMPP integration to show it as you google talk status message (a tutorial and script for this..sometime later)

Basically, instead of displaying “<City name>,<country>”,  this script will display “<Road name>, <areaname>,<cityname>,<country>”

The internals : As soon as the script is executed, It uses the google latitude developer api to get your current co ordinates, then it makes use of the google maps v3 geocoding api (previously called reverse geo coding) to get the info about the co-ordinates of your current location which includes the street name/road name etc.

Steps to add this cool thingy onto your own site:

1. Install google maps application on your GPS mobile phone having GPRS connection (symbian s60,iphone,android)  and then enable Latitude inside google maps app. Ensure that detect location is selected inside the latitude settings under google maps.

2. Goto google latitude web page ( and select Enable and show best available location.

3. In the javascript embed code section of the badge config page, select zoom level automatic, and choose the map type, size of map.

4. Put the generated embed code on your blog to display the map and an approx city level address (we’ll fix this in a moment)

5. Now to display a more accurate address (which includes the roadname,streetnames, areanames) , extract the userid for latitude from the javascript embed code and put it in the below PHP code (line 2)

6.Add this PHP code into a file named “mylatitudelocation.php” and upload it into your webserver root.

7. Add this iframe code into your blog widgets sections to display the accurate address of your current location

<iframe src="mylatitudelocation.php" width="100%" height="50" frameborder="0"></iframe>

Here’s the PHP code:

<?php $latitudeUserid=”-4xxxxx….” // change this and insert your latitude user id (available from the public badge embed code ”

function ago($tm,$rcs = 0) { $cur_tm = time(); $dif = $cur_tm-$tm; $pds = array(‘second’,'minute’,'hour’,'day’,'week’,'month’,'year’,'decade’); $lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600); for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v–); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]); $no = floor($no); if($no <> 1) $pds[$v] .=’s'; $x=sprintf(“%d %s “,$no,$pds[$v]); if(($rcs == 1)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= time_ago($_tm); return $x; }


$locationDetails=json_decode(file_get_contents($latitudeAPI)); $lat=$locationDetails->features[0]->geometry->coordinates[0]; $lng=$locationDetails->features[0]->geometry->coordinates[1]; $timestamp=$locationDetails->features[0]->properties->timeStamp; $when=ago($timestamp);



$locationDetails=json_decode(file_get_contents($geocodeAPI)); $locationString=$locationDetails->results[0]->formatted_address;

echo “$when ago, I was in $locationString”; ?>

Incoming search terms: