photos = (
{
height = 2304;
"html_attributions" = (
"<a href=\"https://maps.google.com/maps/contrib/1152719XX951XXXX0531/photos\">XXX XX</a>"
);
"photo_reference" = "CmRaAAAAFectOxyAKTfvFyP6yIp24z8T6FAidRxYcAMEWYdpeijj6SckncfG9EpgOacw1LrPPrGYN_U6bSiR9D1DffgM";
width = 4096;
},
)
- 如何从photo_reference获取图片的网址或下载图片
最佳答案
您可以使用 Place Photos服务获取与 photo_reference
字符串对应的图像。
请求示例:
对于 swift 中的 iOS,您可以使用等效的 Place Photos使用 placeID
代替服务。请参阅示例代码:
// 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;
}
})
}
})
请注意,下载从 API 返回的图像会违反 Google 的 ToS .查看相关Storing of photoreferences which are returned with place-details
希望这对您有所帮助!
关于ios - 如何快速从google place api获取地点图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58872197/