我擁有GooglePlace PlaceID,並且試圖找出如何將照片加載到UITableView中。 ,谷歌提供了顯示瞭如何將示例代碼加載一個單一的UIImageView,並能正常工作:如何將GooglePlaces照片加載到UITableViewCell中UIImageView
func loadFirstPhotoForPlace(placeID: String) {
GMSPlacesClient.shared().lookUpPhotos(forPlaceID: placeID) { (photos, error) -> Void in
if let error = error {
// TODO: handle the error.
print("Error: \(error.localizedDescription)")
} else {
if let firstPhoto = photos?.results.first {
self.loadImageForMetadata(photoMetadata: firstPhoto)
}
}
}
}
func loadImageForMetadata(photoMetadata: GMSPlacePhotoMetadata) {
GMSPlacesClient.shared().loadPlacePhoto(photoMetadata, callback: {
(photo, error) -> Void in
if let error = error {
// TODO: handle the error.
print("Error: \(error.localizedDescription)")
} else {
print("Loading Image")
self.checkInImageView.image = photo;
// self.attributionTextView.attributedText = photoMetadata.attributions;
}
})
}
我不能從文檔如何直接下載一個地方照片弄清楚。其中許多失敗的嘗試:
if let placeID = checkins[indexPath.row].placeID {
GMSPlacesClient.shared().lookUpPhotos(forPlaceID: placeID) { (photos, error) -> Void in
if let firstPhoto = photos?.results.first {
cell.thumbnailImageView.image = firstPhoto
}
}
}
return cell
非常感謝您的幫助。這很棒! –