地点照片

请选择平台: Android iOS JavaScript 网络服务

地点照片服务是 Places API 的一部分, 可让您向自己的照片添加高品质照片内容的 应用。通过地点照片服务,您可以访问数以百万计的照片 存储在 Places 数据库中。当您使用“地方”获取地点信息时 详情请求,系统将返回相关照片的照片引用 内容。“查找地点”“附近搜索”和“文本搜索”请求也会返回单张照片 参考每个地点的相关情况。使用照片服务 调整参考照片的大小,并将图片调整为最适合您的 应用。

地点照片请求

地点照片请求是一个 HTTP URL,其格式如下:

https://maps.googleapis.com/maps/api/place/photo?parameters

您需要使用某些参数,才能发起搜索请求。按照标准 ,所有参数都使用和号 (&) 字符分隔。通过 下面枚举了各个参数及其可能的值。

Required parameters

  • photo_reference

    A string identifier that uniquely identifies a photo. Photo references are returned from either a Place Search or Place Details request.

  • maxheight or maxwidth

    maxheight specifies the maximum desired height, in pixels, of the image. If the image is smaller than the values specified, the original image will be returned. If the image is larger in either dimension, it will be scaled to match the smaller of the two dimensions, restricted to its original aspect ratio.

    maxwidth specifies the maximum desired width, in pixels, of the image. If the image is smaller than the values specified, the original image will be returned. If the image is larger in either dimension, it will be scaled to match the smaller of the two dimensions, restricted to its original aspect ratio.

    Both the maxheight and maxwidth properties accept an integer between 1 and 1600.

    You must specify either maxheight, or maxwidth, or both.

照片引用

对地点照片服务的所有请求都必须包含 photo_reference, 在对查找地点、附近搜索、文本搜索或地点详情的响应中返回 请求。如果存在photos[] 有相关的照片内容。

注意:返回的照片数量因请求而异。

  • “查找地点”、“附近搜索”或“文本搜索”请求最多返回一个 photo 元素 。
  • 一个“地点详情”请求最多会返回十个 photo 元素。

每个 photo 元素都包含以下字段:

  • photo_reference - 一个字符串,在您查看照片时 执行照片请求
  • height - 图片的最大高度。
  • width - 图片的最大宽度。
  • html_attributions[] - 包含任何必需的提供方说明。这个 字段将始终存在,但可以为空。

照片服务返回的照片来自各种位置, 包括企业主和用户贡献的照片。在大多数情况下 照片可以在不注明提供方的情况下使用,或具有必需的提供方说明 作为图片的一部分添加不过,如果返回的 photo 元素 在 html_attributions 字段中包含值,则必须添加 在应用中显示图片的位置添加额外提供方说明。

下例显示了“地点详情”请求:

curl "https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJcUElzOzMQQwRLuV30nMUEUM&key=YOUR_API_KEY"

响应中的 photos[] 数组示例如下所示。

...
"photos" : [
   {
      "html_attributions" : [],
      "height" : 853,
      "width" : 1280,
      "photo_reference" : "ATJ83zhSSAtkh5LTozXMhBghqubeOxnZWUV2m7Hv2tQaIzKQJgvZk9yCaEjBW0r0Zx1oJ9RF1G7oeM34sQQMOv8s2zA0sgGBiyBgvdyMxeVByRgHUXmv-rkJ2wyvNv17jyTSySm_-_6R2B0v4eKX257HOxvXlx_TSwp2NrICKrZM2d5d2P4q"
   }
...

地点照片示例

示例请求如下所示。此请求将返回参考的 调整其大小,使其宽度不超过 400 像素。

https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photo_reference=ATJ83zhSSAtkh5LTozXMhBghqubeOxnZWUV2m7Hv2tQaIzKQJgvZk9yCaEjBW0r0Zx1oJ9RF1G7oeM34sQQMOv8s2zA0sgGBiyBgvdyMxeVByRgHUXmv-rkJ2wyvNv17jyTSySm_-_6R2B0v4eKX257HOxvXlx_TSwp2NrICKrZM2d5d2P4q&key=YOUR_API_KEY

地点照片响应

成功的地点照片请求的响应将以图片形式显示。该 图片取决于最初提交的照片的类型。

如果您的请求超出了可用配额,服务器将返回一个 HTTP 403 状态,并显示下图以指示配额已 :

“超出配额”图片

如果服务器无法理解您的请求,就会返回 HTTP 400 状态,表明请求无效。导致出现 无效请求包括:

  • 未正确指定提交的照片引用。
  • 请求既不包含 maxwidth,也没有包含 maxheight 参数。
  • 设置了 maxwidthmaxheight 参数的值 发送至 null
  • photo_reference已过期。如果 photo_reference 到期,请 对地点详情的请求后 查找地点附近搜索、 或文本搜索 以获取更新后的 photo_reference 值。