\GoogleMapsTimeZone

A PHP wrapper for the Google Maps TimeZone API.

The Google Maps Time Zone API provides a simple interface to request the time zone for a location on the earth, as well as that location's time offset from UTC. The API provides time offset data for locations on the surface of the earth. Requests for the time zone information are made for a specific latitude/longitude pair and date. The API returns the name of that time zone (in different languages), the time offset from UTC, and the daylight savings offset in a user-selectable format (XML or JSON). In order to be able to use this class, it's necessary to provide an API key or, for business clients, Client ID and signing key.

Summary

Methods
Properties
Constants
__construct()
setFormat()
getFormat()
isFormatJson()
isFormatXml()
setLatitudeLongitude()
getLatitudeLongitude()
setLatitude()
getLatitude()
setLongitude()
getLongitude()
setTimestamp()
getTimestamp()
setLanguage()
getLanguage()
setApiKey()
getApiKey()
setClientId()
getClientId()
setSigningKey()
getSigningKey()
isBusinessClient()
queryTimeZone()
No public properties found
URL_DOMAIN
URL_PATH
URL_HTTPS
FORMAT_JSON
FORMAT_XML
STATUS_SUCCESS
STATUS_NO_RESULTS
STATUS_OVER_LIMIT
STATUS_INVALID_REQUEST
STATUS_REQUEST_DENIED
STATUS_UNKNOWN_ERROR
generateSignature()
timezoneQueryString()
timezoneUrl()
base64EncodeUrlSafe()
base64DecodeUrlSafe()
$format
$latitude
$longitude
$timestamp
$language
$apiKey
$clientId
$signingKey
N/A
No private methods found
No private properties found
N/A

Constants

URL_DOMAIN

URL_DOMAIN

URL_DOMAIN Domain portion of the Google Maps Time Zone API URL.

URL_PATH

URL_PATH

URL_PATH Path portion of the Google Maps Time Zone API URL.

URL_HTTPS

URL_HTTPS

HTTPS URL of the Google Maps Time Zone API.

FORMAT_JSON

FORMAT_JSON

FORMAT_JSON JSON response format.

FORMAT_XML

FORMAT_XML

FORMAT_XML XML response format.

STATUS_SUCCESS

STATUS_SUCCESS

STATUS_SUCCESS No errors occurred, the coordinates were successfully parsed and at lease one time zone was returned.

STATUS_NO_RESULTS

STATUS_NO_RESULTS

STATUS_NO_RESULTS Coordinates parsing was successful, but returned no results. Indicates that no time zone data could be found for the specified position or time. Confirm that the request is for a location on land, and not over water.

STATUS_OVER_LIMIT

STATUS_OVER_LIMIT

STATUS_OVER_LIMIT Over limit of 2,500 (100,000 if premier) requests per day.

STATUS_INVALID_REQUEST

STATUS_INVALID_REQUEST

STATUS_INVALID_REQUEST Invalid request, indicates that the request was malformed or a mandatory parameter was missing

STATUS_REQUEST_DENIED

STATUS_REQUEST_DENIED

Request denied. Indicates that the the API did not complete the request. Confirm that the request was sent over HTTPS instead of HTTP.

STATUS_UNKNOWN_ERROR

STATUS_UNKNOWN_ERROR

STATUS_UNKNOWN_ERROR Unknown server error. May succeed if tried again.

Properties

$format

$format : string

Response format (XML or JSON).

Type

string

$latitude

$latitude : float|string

Latitude to obtain the Time Zone for.

Type

float|string

$longitude

$longitude : float|string

Longitude to obtain the Time Zone for.

Type

float|string

$timestamp

$timestamp : integer

Desired time as seconds since midnight, January 1, 1970 UTC. The Google Maps Time Zone API uses the timestamp to determine whether or not Daylight Savings should be applied. Times before 1970 can be expressed as negative values.

Type

integer

$language

$language : string

Language code in which to return results.

Type

string

$apiKey

$apiKey : string

Google Maps API key to authenticate with.

Type

string

$clientId

$clientId : string

Google Maps API Client ID to authenticate Business clients with.

Type

string

$signingKey

$signingKey : string

Google Maps API Cryptographic signing key to authenticate Business clients with.

Type

string

Methods

__construct()

__construct(float  $latitude, float  $longitude, integer|string  $timestamp, string  $format = self::FORMAT_JSON) : \GoogleMapsTimeZone

Constructor. The request is not executed until `queryTimeZone()` is called.

Parameters

float $latitude

latitude of the location of the location to get timezone information for. Default: 0

float $longitude

longitude of the location of the location to get timezone information for. Default: 0

integer|string $timestamp

point in time to get timezone information from. Default: 0 (current time)

string $format

optional response format (JSON default)

Returns

\GoogleMapsTimeZone

setFormat()

setFormat(string  $format) : \GoogleMapsTimeZone

Set the response format (JSON or XML).

Parameters

string $format

response format

Returns

\GoogleMapsTimeZone

getFormat()

getFormat() : string

Get the response format (JSON or XML).

Returns

string —

response format

isFormatJson()

isFormatJson() : boolean

Returns true if the response format is JSON.

Returns

boolean

isFormatXml()

isFormatXml() : boolean

Returns true if the response format is XML.

Returns

boolean

setLatitudeLongitude()

setLatitudeLongitude(float|string  $latitude, float|string  $longitude) : \GoogleMapsTimeZone

Set the latitude/longitude of the location to get timezone information for

Parameters

float|string $latitude

latitude

float|string $longitude

longitude of the location of the location to get timezone information for

Returns

\GoogleMapsTimeZone

getLatitudeLongitude()

getLatitudeLongitude() : string|false

Get the latitude/longitude of the location of the location to get timezone information for in comma-separated format.

Returns

string|false —

comma-separated coordinates, or false if not set

setLatitude()

setLatitude(float|string  $latitude) : \GoogleMapsTimeZone

Set the latitude of the location of the location to get timezone information for

Parameters

float|string $latitude

latitude of the location of the location to get timezone information for

Returns

\GoogleMapsTimeZone

getLatitude()

getLatitude() : float|string

Get the latitude of the location to get timezone information for

Returns

float|string —

latitude of the location of the location to get timezone information for

setLongitude()

setLongitude(float|string  $longitude) : \GoogleMapsTimeZone

Set the longitude of the location to get timezone information for

Parameters

float|string $longitude

longitude of the location of the location to get timezone information for

Returns

\GoogleMapsTimeZone

getLongitude()

getLongitude() : float|string

Get the longitude of the location to get timezone information for

Returns

float|string —

longitude of the location of the location to get timezone information for

setTimestamp()

setTimestamp(integer|string  $timestamp) : \GoogleMapsTimeZone

Set the point in time to get timezone information for (used to determine whether or not DST is active).

This can be used to get the selected place's timezone in a point in time.

Parameters

integer|string $timestamp

point in time to get timezone information for. Default: 0 (current time)

Returns

\GoogleMapsTimeZone

getTimestamp()

getTimestamp() : integer|string

Get the point in time to get timezone information from (used to determine whether or not DST is active).

Returns

integer|string —

point in time to get timezone information for.

setLanguage()

setLanguage(string  $language) : \GoogleMapsTimeZone

Set the language code in which to return results.

Parameters

string $language

language code

Returns

\GoogleMapsTimeZone

getLanguage()

getLanguage() : string

Get the language code in which to return results.

Returns

string —

language code

setApiKey()

setApiKey(string  $apiKey) : \GoogleMapsTimeZone

Set the API key to authenticate with.

Parameters

string $apiKey

API key

Returns

\GoogleMapsTimeZone

getApiKey()

getApiKey() : string

Get the API key to authenticate with.

Returns

string —

API key

setClientId()

setClientId(string  $clientId) : \GoogleMapsTimeZone

Set the client ID for Business clients.

Parameters

string $clientId

client ID

Returns

\GoogleMapsTimeZone

getClientId()

getClientId() : string

Get the client ID for Business clients.

Returns

string —

client ID

setSigningKey()

setSigningKey(string  $signingKey) : \GoogleMapsTimeZone

Set the cryptographic signing key for Business clients.

Parameters

string $signingKey

cryptographic signing key

Returns

\GoogleMapsTimeZone

getSigningKey()

getSigningKey() : string

Get the cryptographic signing key for Business clients.

Returns

string —

cryptographic signing key

isBusinessClient()

isBusinessClient() : boolean

Whether the request is for a Business client.

Returns

boolean —

Returns true if the request is for a Business client. Otherwise, it returns false.

queryTimeZone()

queryTimeZone(boolean  $raw = false, resource  $context = null) : string|array|\SimpleXMLElement

Execute the timezone request. The return type is based on the requested format: associative array if JSON, SimpleXMLElement object if XML.

Queries are performed using cURL and, if not available, using file_get_contents()

Parameters

boolean $raw

If true, the function returns the raw (string) response. Otherwise, it returns an array or SimpleXMLElement object with the decoded response.

resource $context

stream context from stream_context_create()

Returns

string|array|\SimpleXMLElement —

response in requested format

generateSignature()

generateSignature(string  $pathQueryString) : string

Generate the signature for a Business client timezone request.

Parameters

string $pathQueryString

path and query string of the request

Returns

string —

Base64 encoded signature that's URL safe

timezoneQueryString()

timezoneQueryString() : string

Build the query string with all set parameters of the timezone request.

Returns

string —

encoded query string of the timezone request

timezoneUrl()

timezoneUrl() : string

Build the URL (with query string) of the timezone request.

Returns

string —

URL of the timezone request

base64EncodeUrlSafe()

base64EncodeUrlSafe(string  $value) : string

Encode a string with Base64 using only URL safe characters.

Parameters

string $value

value to encode

Returns

string —

encoded value

base64DecodeUrlSafe()

base64DecodeUrlSafe(string  $value) : string

Decode a Base64 string that uses only URL safe characters.

Parameters

string $value

value to decode

Returns

string —

decoded value