Last active
August 15, 2018 15:03
-
-
Save Burshyn/83ec218e155edd23c34a46e4264fd07b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$addr = 'Columbus,OH,43235'; | |
$maps_api_key = 'insert key here'; | |
/** | |
* Gets the timezone id (eg. America/New_York, America/Detroit) | |
* @param string $address | |
* @return string|bool | |
*/ | |
function get_timezone_from_address($address){ | |
$geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.trim(preg_replace(' ', '+', $address)).'&sensor=false'); | |
$output= json_decode($geocode); | |
$lat = $output->results[0]->geometry->location->lat; | |
$lng = $output->results[0]->geometry->location->lng; | |
$timezone = file_get_contents('https://maps.googleapis.com/maps/api/timezone/json?key='.$maps_api_key.'&location='.$lat.','.$lng.'×tamp='.time()); | |
$tz_result = json_decode($timezone); | |
return isset($tz_result->timeZoneId) ? $tz_result->timeZoneId : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment