google-maps - 在哪里检索 photo_reference 值以发出 Google Places Photos 请求?

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

来自谷歌的Place Photos documentation我应该能够通过向他们的附近搜索、雷达或地点详细信息服务发出请求来检索 photo_reference key 。

我访问了他们的地点详情服务,我收到了一组包含 10 个元素的照片,但这些元素仅包含 heightwidthhtml_attribution 键。我是不是遗漏了一些东西,或者他们的 API 在没有更新他们的文档的情况下发生了变化?

这是我放置详细信息的请求,其中 place 是响应:

export function placeDetailsFetchData(placeId) {
  return (dispatch) => {
    const request = { placeId };
    const service = new google.maps.places.PlacesService(document.createElement('div'));

    service.getDetails(request, (place, status) => {
      if (status == google.maps.places.PlacesServiceStatus.OK) {
        dispatch({
          type: PLACE_DETAILS_FETCH_DATA_SUCCESS,
          place
        });
      } else {
        dispatch(placeDetailsHasErrored(true));
      }
    });
  }
}

这是响应中的照片值:

[
  {
    "height": 3024,
    "html_attributions": [
      "<a href=\"https://maps.google.com/maps/contrib/109733975839515761188/photos\">Chris Bair</a>"
    ],
    "width": 4032
  },
  {
    "height": 2992,
    "html_attributions": [
      "<a href=\"https://maps.google.com/maps/contrib/100217631342523519461/photos\">Samir Soriano</a>"
    ],
    "width": 4000
  },
  {
    "height": 453,
    "html_attributions": [
      "<a href=\"https://maps.google.com/maps/contrib/106775786962992563502/photos\">Frisco Fried</a>"
    ],
    "width": 604
  },
  {
    "height": 5312,
    "html_attributions": [
      "<a href=\"https://maps.google.com/maps/contrib/111414489430298948350/photos\">Tu Lam</a>"
    ],
    "width": 2988
  },
  {
    "height": 1920,
    "html_attributions": [
      "<a href=\"https://maps.google.com/maps/contrib/109551371558914502695/photos\">Kenny Reed</a>"
    ],
    "width": 2560
  },
  {
    "height": 4160,
    "html_attributions": [
      "<a href=\"https://maps.google.com/maps/contrib/110844988640416794228/photos\">Vicious V</a>"
    ],
    "width": 3120
  },
  {
    "height": 2576,
    "html_attributions": [
      "<a href=\"https://maps.google.com/maps/contrib/103079141129202103200/photos\">Romayne Ward</a>"
    ],
    "width": 1932
  },
  {
    "height": 5312,
    "html_attributions": [
      "<a href=\"https://maps.google.com/maps/contrib/103167182117207780142/photos\">Michael C</a>"
    ],
    "width": 2988
  },
  {
    "height": 1836,
    "html_attributions": [
      "<a href=\"https://maps.google.com/maps/contrib/116997882870097389214/photos\">Sam Johnson</a>"
    ],
    "width": 3264
  },
  {
    "height": 4032,
    "html_attributions": [
      "<a href=\"https://maps.google.com/maps/contrib/113862636441079805689/photos\">Wes Wu</a>"
    ],
    "width": 3024
  }
]

最佳答案

google.maps.places.PlacePhoto 对象提供返回地点照片 URL 的方法 getUrl()。使用此方法获取图像的 URL,Maps JavaScript API 不公开照片引用。

查看文档以获取更多详细信息:

https://developers.google.com/maps/documentation/javascript/reference#PlacePhoto

place.photos.forEach(function (placePhoto) {
    var url = placePhoto.getUrl({
        maxWidth: 600,
        maxHeight: 400
    });
});

关于google-maps - 在哪里检索 photo_reference 值以发出 Google Places Photos 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45750833/

相关文章:

google-maps - 谷歌地图地理编码不返回国家

google-maps - Google Chrome 浏览器中的 Google Maps 闪烁问题

javascript - 谷歌地图集群不工作

python - Google oAuth2 python 应用程序无法在线打开登录页面

c# - Google Drive Api-MVC IDataStore

javascript - 谷歌地图不会在 div 容器中显示整个 map

javascript - 在 map 中心显示信息窗口 - Google 避开高速公路

php - Google Map Javascript API v3 : How to auto/easily adjust zoom level based on address detailness? 反之亦然?

api - 我可以在商业项目中使用 Google Weather API 吗?

javascript - 由于 window.handleApiReady 不是函数错误,Google Maps API 未加载