Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在swift中从google place api获取places图像 照片=( { 高度=2304; “html_属性”=( "" ); “照片参考”=“CMRAAAAAFECTOXYAKTVFYP6YIP24Z8T6FAIDRXYCAMEWYDPEIJ6SCKNCFG9EPGOACW1RPPRGYN”6; 宽度=4096; }, ) 如何获取图像的URL,或从照片参考下载图像_Ios_Swift_Xcode_Google Maps_Google Places Api - Fatal编程技术网

Ios 如何在swift中从google place api获取places图像 照片=( { 高度=2304; “html_属性”=( "" ); “照片参考”=“CMRAAAAAFECTOXYAKTVFYP6YIP24Z8T6FAIDRXYCAMEWYDPEIJ6SCKNCFG9EPGOACW1RPPRGYN”6; 宽度=4096; }, ) 如何获取图像的URL,或从照片参考下载图像

Ios 如何在swift中从google place api获取places图像 照片=( { 高度=2304; “html_属性”=( "" ); “照片参考”=“CMRAAAAAFECTOXYAKTVFYP6YIP24Z8T6FAIDRXYCAMEWYDPEIJ6SCKNCFG9EPGOACW1RPPRGYN”6; 宽度=4096; }, ) 如何获取图像的URL,或从照片参考下载图像,ios,swift,xcode,google-maps,google-places-api,Ios,Swift,Xcode,Google Maps,Google Places Api,您可以使用该服务获取与照片参考字符串对应的图像 请求示例: 对于swift中的iOS,您可以使用placeID替代等效服务。请参见示例代码: photos = ( { height = 2304; "html_attributions" = ( "<a href=\"https://maps.google.com/maps/contrib/1152

您可以使用该服务获取与
照片参考
字符串对应的图像

请求示例:

对于swift中的iOS,您可以使用
placeID
替代等效服务。请参见示例代码:

photos = (

  {
                height = 2304;
                "html_attributions" =                 (
                    "<a href=\"https://maps.google.com/maps/contrib/1152719XX951XXXX0531/photos\">XXX XX</a>"
                );
                "photo_reference" = "CmRaAAAAFectOxyAKTfvFyP6yIp24z8T6FAidRxYcAMEWYdpeijj6SckncfG9EpgOacw1LrPPrGYN_U6bSiR9D1DffgM";
                width = 4096;
            },           
)
请注意,下载从API返回的图像将违反谷歌的标准。见相关


希望这有帮助

您好,您是否遇到错误,到目前为止您尝试了什么,您是否启用了API并获取了API密钥?
// Specify the place data types to return (in this case, just photos).
let fields: GMSPlaceField = GMSPlaceField(rawValue: UInt(GMSPlaceField.photos.rawValue))!

placesClient?.fetchPlace(fromPlaceID: "INSERT_PLACE_ID_HERE",
                         placeFields: fields,
                         sessionToken: nil, callback: {
  (place: GMSPlace?, error: Error?) in
  if let error = error {
    print("An error occurred: \(error.localizedDescription)")
    return
  }
  if let place = place {
    // Get the metadata for the first photo in the place photo metadata list.
    let photoMetadata: GMSPlacePhotoMetadata = place.photos![0]

    // Call loadPlacePhoto to display the bitmap and attribution.
    self.placesClient?.loadPlacePhoto(photoMetadata, callback: { (photo, error) -> Void in
      if let error = error {
        // TODO: Handle the error.
        print("Error loading photo metadata: \(error.localizedDescription)")
        return
      } else {
        // Display the first image and its attributions.
        self.imageView?.image = photo;
        self.lblText?.attributedText = photoMetadata.attributions;
      }
    })
  }
})