I recently came by this site WorldTimeEngine where users can search the local time of any place using the name, street address or just latitude and longitude. Since that time I was thinking how easily you can make your own. As long there are some good people over there (For Geocoding API) – its a not a big deal, you know? Lets have a look at the following PHP code.
<?
$place = "Bucharest";
$geodata = getGeoCode($place);
print_r($geodata);
echo getTime($geodata['lat'],$geodata['lng']);
function getTime($lat, $lng)
{
$url = "http://ws.geonames.org/timezone?lat={$lat}&lng={$lng}";
$timedata = file_get_contents($url);
$sxml = simplexml_load_string($timedata);
return $sxml->timezone->time;
}
function getGeoCode($address)
{
$_url = 'http://api.local.yahoo.com/MapsService/V1/geocode';
$_url .= sprintf('?appid=%s&location=%s',"orchid_geocode",rawurlencode($address));
$_result = false;
if($_result = file_get_contents($_url)) {
preg_match('!<Latitude>(.*)</Latitude><Longitude>(.*)</Longitude>!U', $_result, $_match);
$lng = $_match[2];
$lat = $_match[1];
return array("lat"=>$lat,"lng"=>$lng,"address"=>$address);
}
else
return false;
}
?>
Changing the variable “$place” to “Bucharest”,”Dhaka”, “Toronto” and “Oslo” gives me the following result
Array
(
[lat] => 44.434200
[lng] => 26.102955
[address] => Bucharest
)
2008-03-01 08:41
Array
(
[lat] => 23.709801
[lng] => 90.407112
[address] => Dhaka
)
2008-03-01 12:42
Array
(
[lat] => 43.648565
[lng] => -79.385329
[address] => Toronto
)
2008-03-01 01:42
Array
(
[lat] => 59.912280
[lng] => 10.749980
[address] => Oslo
)
2008-03-01 07:43
Nice, Huh?
Nice 🙂 i’m gonna try it now.
রিজাল্টটা অণ্য ভাবে দেখালে ভালো হত । 🙂
Google has an API for this, too:
http://www.google.com/search?q=time:bucharest
@geoff
Thats true only for known places. And you cannot search time by Lat and Lng
You can achive the same result using the google maps Api. Actually microsoft has also a maps service and I think they also offer geocoding service. I prefer the googleMaps api.
I’ve found another idea, how to use WorldTimeEngine to forget time-zone issues much more friendly for the users.
I’ve found another idea, how to use WorldTimeEngine to forget time-zone issues much more friendly for the users.
http://realitydrivendeveloper.com/2009/08/worldtimeengine-how-to-show-all-times-in-users-local-time-zone/