【问题标题】:Google Places JS API weekday_textGoogle Places JS API weekday_text
【发布时间】:2017-02-23 18:14:31
【问题描述】:

有人知道为什么我的“nearbySearch”谷歌地方搜索缺少数据吗?

当我使用地点 API 进行附近搜索时,每个 weekday_text 数组都返回为空,但是当我对初始搜索中的某个位置执行“getDetails”请求时,将返回 weekday_text。

http://codepen.io/anon/pen/RGBVJR

var map;
var service;

// Nearby search
var showPosition = function() {

  var geolocation = new google.maps.LatLng(51.5074, -0.1278);

  map = new google.maps.Map(document.getElementById('map'), {
    center: geolocation,
    zoom: 15
  });

  var request = {
    location: geolocation,
    radius: '500',
    types: ['bar']
  };

  service = new google.maps.places.PlacesService(map);
  service.nearbySearch(request, callback);

};
showPosition();

function callback(results, status) {

  if (status == google.maps.places.PlacesServiceStatus.OK) {
    console.log(results);
  }

}

// Direct location check
function altTest() {

  var map = new google.maps.Map(document.getElementById('map'), {
    center: new google.maps.LatLng(51.5074, -0.1278),
    zoom: 15
  });

  var service = new google.maps.places.PlacesService(map);

  service.getDetails({
    placeId: 'ChIJ78fbAc8EdkgRWG1dhffz9AY'
  }, function (place, status) {
    if (status === google.maps.places.PlacesServiceStatus.OK) {
      console.log(place.opening_hours.weekday_text);
    }
  });

}

altTest();
<div id="map">
</div>
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>

请查看 console.logs 以查看数据差异。

任何想法为什么会这样?我宁愿不必执行第二个 API 请求来检索工作日请求。

谢谢,

汤姆

【问题讨论】:

    标签: javascript api google-maps google-maps-api-3 google-places-api


    【解决方案1】:

    nearbySearch 返回一个 PlaceResult 对象数组。

    如您所见here,PlaceResult 没有 weekday_text 属性。

    【讨论】:

    • 不幸的是,文档还指出详细信息请求返回相同类型的对象。我会说文档已经过时了。
    • 开始看起来我需要进行许多 api 调用。有没有人找到一种有效的方法来做到这一点?
    猜你喜欢
    • 1970-01-01
    • 2015-06-26
    • 2017-02-08
    • 1970-01-01
    • 1970-01-01
    • 2016-04-02
    • 2014-03-18
    • 2012-02-22
    • 1970-01-01
    相关资源
    最近更新 更多