Google 地点 API Web 服务显示 photo_reference,但 Javascript 库不显示

Google Places API Web Service shows photo_reference, but Javascript library doesn't

我正在构建一个基本的地点搜索页面,我正在为其使用 Google 地点 Javascript 库 (text search)。我确实得到了一个 "photo" 元素,但我注意到 "photo_reference" 字段是空的。这里有一个示例请求:

var service = new google.maps.places.PlacesService(this.map);
service.textSearch({query: 'harbour bridge'}, this.callback.bind(this));

回复:

{
   "formatted_address":"Sydney Harbour Bridge, Sydney NSW, Australia",
   "geometry":{
      "location":{
         "lat":-33.8523063,
         "lng":151.21078710000006
      }
   },
   "icon":"https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
   "id":"e22913360d0b946d099c7a32a77a95e49f9ead66",
   "name":"Sydney Harbour Bridge",
   "photos":[{
     "height":4000,
     "html_attributions":["<a href=\"https://maps.google.com/maps/contrib/113178678511744469415/photos\">Jasper Straver</a>"],
     "width":6000
   }],
   "place_id":"ChIJ49XqJV2uEmsRPsTAF7eOlGg",
   "rating":4.7,
   "reference":"[...]",
   "types":["point_of_interest", "establishment"],
   "html_attributions":[]
}

如果我使用 Web 服务执行相同的请求,我会得到 photo_reference。示例:

https://maps.googleapis.com/maps/api/place/textsearch/json?key=[...]&query=harbour%20bridge

回复:

{
     "formatted_address" : "Sydney Harbour Bridge, Sydney NSW, Australia",
     "geometry" : {
        "location" : {
           "lat" : -33.8523063,
           "lng" : 151.2107871
        }
     },
     "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
     "id" : "e22913360d0b946d099c7a32a77a95e49f9ead66",
     "name" : "Sydney Harbour Bridge",
     "photos" : [
        {
           "height" : 4000,
           "html_attributions" : ["\u003ca href=\"https://maps.google.com/maps/contrib/113178678511744469415/photos\"\u003eJasper Straver\u003c/a\u003e"],
           "photo_reference" : "CmRdAAAAY-WUame_CRFnMFmUN4UlvFHI7o3tQOqXJxTkjQINgzMQOOheBzLPIm43dlIAIkhFyugFAw8fnf-ItEiUp1j48B23sCDFRtCWM123euhDif_P1jYkvFAjDrPxq1rCnmi2EhCt6LpVl5W-AKPLRkW_tzs6GhRlG4dx2CVuTNZZMFFo3eYMSFWzGg",
           "width" : 6000
        }
     ],
     "place_id" : "ChIJ49XqJV2uEmsRPsTAF7eOlGg",
     "rating" : 4.7,
     "reference" : "[...]",
     "types" : [ "point_of_interest", "establishment" ]
  }

为什么 JS 和 Web 服务之间有区别 API?如何从 JS 库中获取 photo_reference? (我不想为每个搜索结果发出 getDetails(...) 请求)

谢谢!

photo_reference 用于 Google 个地方 API Web 服务 。使用 Places Javascript 库,您只需在 photos 数组的元素上调用 getUrl,例如place.photos[0].getUrl({maxWidth: 1000}).

与网络服务一样,搜索结果不会超过 1 张照片。