16 octubre 2010

PHP code to get timezone from latitude and longitude

It is as simple as taking your latitude and longitude from your location and calling geonames.org webservice using the code below

Enjoy.

Update: sorry, "<" was not replaced by "& lt;" and neither did ">" by "& gt;"
$latitude = .....
$longitude = .....
$geonames_call ="http://ws.geonames.org/timezone?lat=" . $latitude . "&lng=" . $longitude;
$output = file_get_contents( $geonames_call );
preg_match("/<timezoneId>(.*?)<\/timezoneId>/ims", $output, $matches);
$timezone = $matches[1];
echo "Timezone = ", $timezone, "<br/>
";
Publicar un comentario