如何使用 JavaScript 和 Google 地图 API 获取某个地点的时区偏移量?
How to get the timezone offset of a place using JavaScript with the Google Maps API?
我是编程新手,目前正在尝试从 Google 自动完成搜索中提取 UTC 时区偏移值。
目前,我可以使用以下代码从自动完成选择中提取 JavaScript 中的纬度和经度:
var item_Lat = place.geometry.location.lat();
var item_Lng = place.geometry.location.lng();
什么对时区偏移有用?
为此,您需要使用 google 中的时区 api。
由于您已经有了地点的经纬度,您可以简单地将这些作为查询参数连同您当前地点的时间戳插入以下 api 请求中。
https://maps.googleapis.com/maps/api/timezone/json?location=38.908133
,-77.047119
×tamp=1458000000
&key=YOUR_API_KEY
可以找到更多信息 here。
我是编程新手,目前正在尝试从 Google 自动完成搜索中提取 UTC 时区偏移值。
目前,我可以使用以下代码从自动完成选择中提取 JavaScript 中的纬度和经度:
var item_Lat = place.geometry.location.lat();
var item_Lng = place.geometry.location.lng();
什么对时区偏移有用?
为此,您需要使用 google 中的时区 api。 由于您已经有了地点的经纬度,您可以简单地将这些作为查询参数连同您当前地点的时间戳插入以下 api 请求中。
https://maps.googleapis.com/maps/api/timezone/json?location=38.908133
,-77.047119
×tamp=1458000000
&key=YOUR_API_KEY
可以找到更多信息 here。