function _tzfield_geofield_get_timezone in Time Zone Field 7
Return timezone by location.
1 call to _tzfield_geofield_get_timezone()
- tzfield_geofield_field_attach_presave in tzfield_geofield/
tzfield_geofield.module - Implements hook_field_attach_presave().
File
- tzfield_geofield/
tzfield_geofield.module, line 70 - Populate a time zone field from Geofield.
Code
function _tzfield_geofield_get_timezone($lat, $lon) {
$response = file_get_contents(url('https://maps.googleapis.com/maps/api/timezone/json', array(
'query' => array(
'location' => $lat . ',' . $lon,
'timestamp' => REQUEST_TIME,
'sensor' => 'false',
// To make API requests, you must set this API key variable.
'key' => variable_get('tzfield_geofield_google_timezone_api_key'),
),
)));
$json = json_decode($response);
if (!isset($json->errorMessage)) {
return $json->timeZoneId;
}
watchdog('tzfield_geofield', 'Google time zone API error %status %error_message', array(
'%status' => $json->status,
'%error_message' => $json->errorMessage,
), WATCHDOG_ERROR);
}