Google Maps API v3 Places Library returning undefined utc_offset

回眸只為那壹抹淺笑 提交于 2019-12-06 03:18:31

As you mentioned in only works when there are generic terms like "pizza". What I've done is if it is undefined, I call the Google TimeZone API to get the info. I've put a code sample below, but you can see my solution on GitHub as well, https://github.com/pushpickup/pushpickup/blob/master/client/views/games/creategame/select-location.js#L13

if (place.utc_offset === void 0) {
  timeStamp = (Date.now() || new Date().getTime())/1000;
  timeZoneApiRequestUrl = "https://maps.googleapis.com/maps/api/timezone/json?location=" +
                            place.geometry.location.lat() + "," + place.geometry.location.lng() +
                            "&timestamp=" + timeStamp + "&key=YOUR_API_KEY"

  $.get(timeZoneApiRequestUrl, function( data ) {
    var utcOffset = (data.rawOffset + data.dstOffset || 0) / 3600;
    console.log("UTC offset is " + utcOffset + " hours")
  }); // expand this to handle errors, just doing a get with success for now as a POC
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!