Access your Google Latitude position from PHP
June 22, 2009 — Florent ClairambaultThe code to access your Google Latitude position is even simpler in PHP than it is in .Net :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <?PHP header('Content-Type: text/plain'); $userId = '5616045291659744796'; if ( $_GET['user'] ) { if ( is_numeric( $_GET['user'] ) ) $userId = $_GET['user']; else exit('This isn\'t a valid user id.'); } $url = 'http://www.google.com/latitude/apps/badge/api?user='.$userId.'&type=json'; // We get the content $content = file_get_contents( $url ); // We convert the JSON to an object $json = json_decode( $content ); $coord = $json->features[0]->geometry->coordinates; $timeStamp = $json->features[0]->properties->timeStamp; if ( ! $coord ) exit('This user doesn\'t exist.'); $date = date( 'd/m/Y H:i:s', $timeStamp ); $lat = $coord[1]; $lon = $coord[0]; echo $date.' : '.$lat.' x '.$lon; ?> |
This program is available for testing here. It requires PHP 5.2.0 to run the json_decode method.
I think this is the power of PHP, you can make some powerful code in no time. The drawback is that it’s really slow, and it becomes even slower if you begin to use heavy objects (and objects are often heavy). And I personally think it’s much easier and safer to debug and maintain complex .Net programs than complex PHP programs.
By the way, you can generate your google badge userid that you can then use for the API here. (thank you Neavilag for this comment)
GD Star Rating
loading...
loading...
June 24, 2009 at 3:06 am
Pas mal comme snippet, quelques lignes… mais utile ! Merci
loading...
July 13, 2010 at 9:05 pm
Thanks for the post, how can i know my userid or any of my friends ?
regards
loading...
July 13, 2010 at 9:56 pm
Hi Neavilag,
Your usedid is generated for your public google badge here : https://www.google.com/latitude/apps/badge .
But you don’t have to use it publicly, you can keep this userid to yourself.
loading...
July 13, 2010 at 11:59 pm
Thanks Florent…
)) already there…
loading...