直接从国家和州Google API获取时区 [英] Get timezone directly from Country and State Google API

查看:106
本文介绍了直接从国家和州Google API获取时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从国家和州(例如澳大利亚/悉尼)获取时区.此处有一个答案,该答案首先获取坐标,然后请求使用坐标作为参数的时区.

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.

但是我问是否有直接通过任何Google API做到这一点的方法?

But I'm asking is there a direct way of doing this via any google API?

推荐答案

是的,您可以使用

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.

Google Maps时区API提供了地球表面位置的时间偏移数据.您需要特定纬度/经度对和日期的时区信息.该API返回该时区的名称,与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.

时区API请求被构造为URL字符串.API返回地球上某个点的时区数据,由纬度/经度对指定.请注意,时区数据可能不适用于诸如海洋之类的水上位置.

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.

样品请求:

https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331161200&key=YOUR_API_KEY

示例响应:

{
"dstOffset" : 0,
"rawOffset" : -28800,
"status" : "OK",
"timeZoneId" : "America/Los_Angeles",
"timeZoneName" : "Pacific Standard Time"
}

您可以尝试使用入门文档来播放和熟悉API: https://developers.google.com/maps/documentation/timezone/start

You can try the Getting Started document for you to play and familiarize the API: https://developers.google.com/maps/documentation/timezone/start

这篇关于直接从国家和州Google API获取时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆