简体   繁体   中英

How to get the timezone offset of a place using JavaScript with the Google Maps API?

I'm newer to programming and am currently trying to pull the UTC timezone offset value from a Google Autocomplete search.

Currently, I am able to pull the latitude and longitude in JavaScript from the autocomplete selection using this code:

var item_Lat = place.geometry.location.lat();
var item_Lng = place.geometry.location.lng();

What would work for the timezone offset?

You need to use the Timezone api from google for this purpose. Since you already have the latitude and longitude of the place , you can simply plug these as query parameters along with the timestamp of your current place in the following api request.

https://maps.googleapis.com/maps/api/timezone/json?location= 38.908133 , -77.047119 &timestamp= 1458000000 &key= YOUR_API_KEY

More information can be found here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM