Time Zone API では、地表のさまざまな地点の時間オフセット データを取得できます。特定の緯度と経度のペアのタイムゾーン情報をリクエストします。API は、タイムゾーンの名前、UTC からのオフセット、夏時間のオフセットを返します。
リクエストとレスポンスの例
HTTPS インターフェースを介して Time API にアクセスします。その際、リクエストを URL 文字列として作成し、緯度と経度の座標で location
を指定して、timestamp
で日付を指定し、API キーを指定します。
次のクエリは、米国ネバダ州のタイムゾーン リクエストを実行します。タイムスタンプは 2012 年 3 月 8 日に設定されています。
URL
https://maps.googleapis.com/maps/api/timezone/json ?location=39.6034810%2C-119.6822510 ×tamp=1331161200 &key=YOUR_API_KEY
cURL
curl -L -X GET 'https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810%2C-119.6822510×tamp=1331161200&key=YOUR_API_KEY'
JavaScript
var axios = require('axios'); var config = { method: 'get', url: 'https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810%2C-119.6822510×tamp=1331161200&key=YOUR_API_KEY', headers: { } }; axios(config) .then(function (response) { console.log(JSON.stringify(response.data)); }) .catch(function (error) { console.log(error); });
Python
import requests url = "https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810%2C-119.6822510×tamp=1331161200&key=YOUR_API_KEY" payload={} headers = {} response = requests.request("GET", url, headers=headers, data=payload) print(response.text)
Java
OkHttpClient client = new OkHttpClient().newBuilder() .build(); MediaType mediaType = MediaType.parse("text/plain"); RequestBody body = RequestBody.create(mediaType, ""); Request request = new Request.Builder() .url("https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810%2C-119.6822510×tamp=1331161200&key=YOUR_API_KEY") .method("GET", body) .build(); Response response = client.newCall(request).execute();
Ruby
require "uri" require "net/http" url = URI("https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810%2C-119.6822510×tamp=1331161200&key=YOUR_API_KEY") https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) response = https.request(request) puts response.read_body
Go
package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510×tamp=1331161200&key=YOUR_API_KEY" method := "GET" client := &http.Client { } req, err := http.NewRequest(method, url, nil) if err != nil { fmt.Println(err) return } res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) }
Postman
OpenAPI 仕様も Postman コレクションとして入手できます。
Postman で実行するこれをテストするには、ウェブブラウザに URL を入力します(YOUR_API_KEY
は実際の API キーに置き換えてください)。レスポンスには、指定されたロケーションと日付 (timestamp)
のタイムゾーン データが含まれます。
デベロッパー ガイドで、リクエスト URL と利用可能なパラメータの作成とレスポンスについて理解する方法をご確認ください。
JSON 形式のレスポンス例を次に示します。
JSON
{ "dstOffset": 0, "rawOffset": -28800, "status": "OK", "timeZoneId": "America/Los_Angeles", "timeZoneName": "Pacific Standard Time", }
XML
<TimeZoneResponse> <status>OK</status> <raw_offset>-28800.0000000</raw_offset> <dst_offset>0.0000000</dst_offset> <time_zone_id>America/Los_Angeles</time_zone_id> <time_zone_name>Pacific Standard Time</time_zone_name> </TimeZoneResponse>
クライアント ライブラリを使用してコーディングを開始する
クライアント ライブラリを使用すると、認証、リクエストのスロットル調整、自動再試行などの一般的なタスクのシンプルなネイティブ実装が提供され、Google Maps ウェブサービス API での開発が容易になります。Time Zone API は、Google マップサービス用の Java Client、Python Client、Go Client、Node.js クライアントで利用可能です。
認証、割り当て、料金、ポリシー
認証
Time Zone API を使用するには、まず API を有効にして、適切な認証情報を取得する必要があります。詳しくは、Google Maps Platform スタートガイドをご確認ください。
割り当てと料金
Time Zone API の割り当てと料金の詳細については、使用量と課金のページをご覧ください。
ポリシー
Time Zone API を使用する場合は、API ポリシーに従う必要があります。
詳細
Time Zone API で、デフォルトの英語以外の言語で結果を返せるように言語パラメータを設定することもできます。その他の例や詳細については、Time Zone API デベロッパー ガイドをご覧ください。
Time Zone API デベロッパー ガイドは、Google Maps Platform API のひとつで提供された地図に、時刻データを追加する必要があるウェブサイトやモバイル デベロッパーを対象としています。利用可能なパラメータに関する API とリファレンス資料の使用方法を紹介します。