特定地点id的照片



如何获取特定"place_id"的所有图片?

当我检索特定位置的"地点"列表时,我只能访问一个特定的图像"photo_reference"。

我想通过它的"places_id"(更具体的搜索)来显示地方的详细信息,但API函数的结果没有显示相关的图片。如果你正在浏览谷歌放置"id"具体的地方,会出现更多的图像。我怎样才能找回它们?

感谢

当API没有返回任何照片时,您可以使用街景图像API。您可以使用您从街道视图API请求中的位置响应中接收到的坐标,链接如下:

https://maps.googleapis.com/maps/api/streetview?size=600x300&location=46.414382,10.013988&key=YOUR_API_key

您可能需要在google开发者控制台中启用街道视图api以及位置api。

街景参考:https://developers.google.com/maps/documentation/streetview/?hl=en

假设您有一个id为attributions的元素和一个id为image的元素,那么您可以使用JavaScriptneneneba API执行以下操作。代码笔:http://codepen.io/anon/pen/adooRp

  var attributions = document.getElementById("attributions");   
  var service = new google.maps.places.PlacesService(attributions);
  var request = {
      placeId: 'ChIJ10KlwAdzXg0RsH56kZsfcHs'   
  };
  service.getDetails(request, function(place, status) {
      if (status == google.maps.places.PlacesServiceStatus.OK) {
          var lat = place.geometry.location.lat();
          var lng = place.geometry.location.lng();
          var src = "https://maps.googleapis.com/maps/api/streetview?size=600x300&location="
+ lat + "," + lng + "&key=YOUR_API_KEY_HERE";
          document.getElementById("image").src = src;
      }   
  });

最新更新