Google Places JS API weekday_text

时间:2016-10-14 10:32:51

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

有谁知道为什么我的" nearbySearch"谷歌地方搜索缺少数据?

当我使用places 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>
&#13;
&#13;
&#13;

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

为什么会出现这种情况?我宁愿不用第二个API请求来检索工作日请求。

谢谢,

汤姆

1 个答案:

答案 0 :(得分:1)

nearbySearch返回一个PlaceResult对象数组。

正如您所看到的here,PlaceResult没有提供weekday_text属性。