How to get opening hours from google places api

我们两清 提交于 2019-12-04 06:14:52

Use a try-catch-statement:

try{
  open = place.opening_hours.periods[1].open.time;
}
catch(e){
  open='No work time';
}

...otherwise you will get an error when any of following is undefined:

  • place.opening_hours
  • place.opening_hours.periods
  • place.opening_hours.periods[1]
  • place.opening_hours.periods[1].open

But however, the documentation seems to be misleading, it suggests that the returned results are placeDetails. But that's not the fact , you need a further request for each place to request the placeDetails(which will contain the opening_hours.periods, when available)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!