问题
I need to get the timezone from just country and state (E.g. Australia/Sydney). There's an answer here that gets the coordinates first then requests for the timezone using the coordinates as params.
But I'm asking is there a direct way of doing this via any google API?
回答1:
Yes, you can use the Time Zone 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 Google Maps Time Zone API provides time offset data for locations on the surface of the earth. You request the time zone information for a specific latitude/longitude pair and date. The API returns the name of that time zone, the time offset from UTC, and the daylight savings offset.
Time Zone API requests are constructed as a URL string. The API returns time zone data for a point on the earth, specified by a latitude/longitude pair. Note that time zone data may not be available for locations over water, such as oceans or seas.
Sample Request:
https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510×tamp=1331161200&key=YOUR_API_KEY
Sample Response:
{
"dstOffset" : 0,
"rawOffset" : -28800,
"status" : "OK",
"timeZoneId" : "America/Los_Angeles",
"timeZoneName" : "Pacific Standard Time"
}
You can try the Getting Started document for you to play and familiarize the API: https://developers.google.com/maps/documentation/timezone/start
来源:https://stackoverflow.com/questions/38045745/get-timezone-directly-from-country-and-state-google-api