我在哪里检索 photo_reference 值以发出 Google 地方信息照片请求? [英] Where do I retrieve the photo_reference value to make a Google Places Photos request?

查看:11
本文介绍了我在哪里检索 photo_reference 值以发出 Google 地方信息照片请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 Google 的 Place Photos 文档我应该能够检索到 photo_reference 键,用于向他们附近的搜索、雷达或地点详细信息服务提出请求.

我正在访问他们的地点详情服务,我收到了一组包含 10 个元素的照片,但这些元素仅包含 heightwidthhtml_attribution 键.我是否在这里遗漏了某些东西,或者他们的 API 更改了而没有更新他们的文档?

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

导出函数 placeDetailsFetchData(placeId) {返回(调度)=>{const request = { placeId };const service = new google.maps.places.PlacesService(document.createElement('div'));service.getDetails(request, (place, status) => {如果(状态 == google.maps.places.PlacesServiceStatus.OK){派遣({类型:PLACE_DETAILS_FETCH_DATA_SUCCESS,地方});} 别的 {dispatch(placeDetailsHasErrored(true));}});}}

这是响应中的照片值:

<预><代码>[{高度":3024,html_attributions":["<a href="https://maps.google.com/maps/contrib/109733975839515761188/photos">Chris Bair</a>"],宽度":4032},{高度":2992,html_attributions":["<a href="https://maps.google.com/maps/contrib/100217631342523519461/photos">Samir Soriano</a>"],宽度":4000},{高度":453,html_attributions":["<a href="https://maps.google.com/maps/contrib/106775786962992563502/photos">Frisco Fried</a>"],宽度":604},{高度":5312,html_attributions":["<a href="https://maps.google.com/maps/contrib/111414489430298948350/photos">Tu Lam</a>"],宽度":2988},{高度":1920,html_attributions":["<a href="https://maps.google.com/maps/contrib/109551371558914502695/photos">肯尼·里德</a>"],宽度":2560},{高度":4160,html_attributions":["<a href="https://maps.google.com/maps/contrib/110844988640416794228/photos">Vicious V</a>"],宽度":3120},{高度":2576,html_attributions":["<a href="https://maps.google.com/maps/contrib/103079141129202103200/photos">Romayne Ward</a>"],宽度":1932},{高度":5312,html_attributions":["<a href="https://maps.google.com/maps/contrib/103167182117207780142/photos">Michael C</a>"],宽度":2988},{高度":1836,html_attributions":["<a href="https://maps.google.com/maps/contrib/116997882870097389214/photos">山姆约翰逊</a>"],宽度":3264},{高度":4032,html_attributions":["<a href="https://maps.google.com/maps/contrib/113862636441079805689/photos">Wes Wu</a>"],宽度":3024}]

解决方案

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

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

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

place.photos.forEach(function (placePhoto) {var url = placePhoto.getUrl({最大宽度:600,最大高度:400});});

From Google's Place Photos documentation I should be able to retrieve a photo_reference key from making a request to their nearby search, radar, or place details services.

I'm hitting their place details service, and I'm receiving an array of photos with 10 elements, but these elements only contain the height, width, and html_attribution keys. Am I missing something here or has their API changed without updating their documentation?

Here's my request to place details, where place is the response:

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));
      }
    });
  }
}

Here's the photos value in the response:

[
  {
    "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
  }
]

解决方案

The google.maps.places.PlacePhoto object provides the method getUrl() that returns URL of the place photo. Use this method to get the URL of image, Maps JavaScript API doesn't expose a photo reference.

Have a look at documentation for further details:

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

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

这篇关于我在哪里检索 photo_reference 值以发出 Google 地方信息照片请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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