Get timezone directly from Country and State Google API

眉间皱痕 提交于 2021-01-29 05:31:44

问题


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&timestamp=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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!