从Google Places API获取photo_reference值

时间:2018-07-13 10:16:07

标签: javascript google-places

我们希望通过此处所述的呼叫显示来自Google的照片: https://developers.google.com/places/web-service/photos

要获取地点信息,我们使用以下示例:

function initMap() {
   var pyrmont = {lat: -33.866, lng: 151.196};

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

   var service = new google.maps.places.PlacesService(map);
   service.nearbySearch({
      location: pyrmont,
      radius: 500,
      type: ['store']
   }, processResults);
}

function processResults(results, status, pagination) {
   if (status !== google.maps.places.PlacesServiceStatus.OK) {
      return;
   } else {
      console.log(results);
   }
}

结果参数似乎并不包含photo_reference字段。使用service.getDetails时也不是这种情况。该字段仅出现在google内部通话的响应中(https://maps.googleapis.com/maps/api/place/js/PlaceService.GetPlaceDetails?...)

是否有可能以某种方式获取该字段?

预先感谢

编辑:

传递给results的{​​{1}}参数为每个结果对象包含一个photos对象,该对象本身包含每个对象都有一个名为getUrl的方法。该方法返回一个临时链接以显示照片其中包含photo_reference。可以提取参考值。

示例:

processResults()

但是这很混乱,可能不是真正做到这一点的方法。因此问题仍然存在。

0 个答案:

没有答案
相关问题