Google Place API-如何获取开放时间 [英] Google Place API - How to retrieve opening hours

查看:120
本文介绍了Google Place API-如何获取开放时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以获取Google Place的开放时间? 我在几个论坛和文档中寻找过,但没有发现任何东西(也许只有foursquare API公开了该信息)

Google不公开此信息吗?

是否有任何服务可以公开此信息? (facebook地点,是的,等等)

非常感谢所有回复

阿尔贝托

解决方案

我想现在可以做到这一点:

https://developers.google.com/places/documentation/details#PlaceDetailsResults 如果您不想创建自己的Places API密钥或安装节点,请

请参见此要点以获取示例输出.

var request = require('request');
// $ npm install request
// Test code to demonstrate parsing operating hours from Google Places
// https://developers.google.com/places/documentation/details#PlaceDetailsResults

// most establishments specify one set of hours per day:
var testRef = 'CnRoAAAAhWUhxi1GkTSCMDMb2piX2JgQzcMv1v6Bv1rDWAINnWrI6T_Vkn3KRpnI5rTd2NI2f0zy4R8n6vRDoj-qTewKa3r70riORCUF-HNU1FLtI3MHNSw8z0_6fBni6hTuXCsGw1SD44I85ha9GVZOZlAS_hIQuNBJmgTHh9bCC4XvdLiDCBoUfmY1ozj0FW-TvurbmryBdwAvoPo';

// 24 hour restaurants only have one period with open:0000 and no close
var _24hrRef = 'CnRpAAAAcKNSNO0jxSONMAPx7EjG6BdgqhWbzDh1rOWM8I1HJZikRYPxW4L1A1ZwH4HEEBy5diKyXT1nRs2a7cxZK7S4oOr5HrTKewV_WGYdy-CuumuwLzSeckgXWvRdIRCW49JXUeJsqhkhtATHyyIDUYWW4RIQ38ZaUuG8A3WbRrsHLwmwDRoUfmtzSsfki7v8iBmUAZgrUIoVOt0'

// Restaurants that are closed on some days will have fewer than 7 open:close pairs

getPlaceDetails(_24hrRef, function(err, result){
  if(err){ 
    return console.log('Request error: '+err+result);
  };
  console.log('Request successful:')
  console.log(JSON.stringify(result.opening_hours, null, 2));
});

function getPlaceDetails(ref,callback){
  var config = {   
    uri:'https://maps.googleapis.com/maps/api/place/details/json',
    qs: {
      key: "SOME-VALID-GOOGLEPLACES-API-KEY",
      // Generate a new Simple API key and plug it in
      // https://code.google.com/apis/console
      reference:ref,
      sensor:'false',
    }
  };
  request(config, function(err, response, body){
    if(err){ return callback(err) };
    var res = JSON.parse(body);
    switch(res.status){
      case "OK":           return callback(null, res.result);
      case "ZERO_RESULTS": return callback(null, res.result);
      default:             return callback(res.status, body);
    };
  });
};

There a way to get the opening hours of google place? I looked for in a several forum and documentations but i didn't find nothing (perhaps only foursquare API expose that information)

Google doesn't expose this information?

Is there any service that expose this? (facebook place, yelp, ecc..)

Thanks so much for all reply

Alberto

解决方案

I guess this is possible now:

https://developers.google.com/places/documentation/details#PlaceDetailsResults

See this gist for sample output if you don't want to make your own Places API key or install node.

var request = require('request');
// $ npm install request
// Test code to demonstrate parsing operating hours from Google Places
// https://developers.google.com/places/documentation/details#PlaceDetailsResults

// most establishments specify one set of hours per day:
var testRef = 'CnRoAAAAhWUhxi1GkTSCMDMb2piX2JgQzcMv1v6Bv1rDWAINnWrI6T_Vkn3KRpnI5rTd2NI2f0zy4R8n6vRDoj-qTewKa3r70riORCUF-HNU1FLtI3MHNSw8z0_6fBni6hTuXCsGw1SD44I85ha9GVZOZlAS_hIQuNBJmgTHh9bCC4XvdLiDCBoUfmY1ozj0FW-TvurbmryBdwAvoPo';

// 24 hour restaurants only have one period with open:0000 and no close
var _24hrRef = 'CnRpAAAAcKNSNO0jxSONMAPx7EjG6BdgqhWbzDh1rOWM8I1HJZikRYPxW4L1A1ZwH4HEEBy5diKyXT1nRs2a7cxZK7S4oOr5HrTKewV_WGYdy-CuumuwLzSeckgXWvRdIRCW49JXUeJsqhkhtATHyyIDUYWW4RIQ38ZaUuG8A3WbRrsHLwmwDRoUfmtzSsfki7v8iBmUAZgrUIoVOt0'

// Restaurants that are closed on some days will have fewer than 7 open:close pairs

getPlaceDetails(_24hrRef, function(err, result){
  if(err){ 
    return console.log('Request error: '+err+result);
  };
  console.log('Request successful:')
  console.log(JSON.stringify(result.opening_hours, null, 2));
});

function getPlaceDetails(ref,callback){
  var config = {   
    uri:'https://maps.googleapis.com/maps/api/place/details/json',
    qs: {
      key: "SOME-VALID-GOOGLEPLACES-API-KEY",
      // Generate a new Simple API key and plug it in
      // https://code.google.com/apis/console
      reference:ref,
      sensor:'false',
    }
  };
  request(config, function(err, response, body){
    if(err){ return callback(err) };
    var res = JSON.parse(body);
    switch(res.status){
      case "OK":           return callback(null, res.result);
      case "ZERO_RESULTS": return callback(null, res.result);
      default:             return callback(res.status, body);
    };
  });
};

这篇关于Google Place API-如何获取开放时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆