我似乎无法从PlacePhotoMetadata
对象中获取url。调试器显示那里有一个URL,但我似乎无法访问它。如何访问对象中的URL?
val placeId = "ChIJa147K9HX3IAR-lwiGIQv9i4"
val photoMetadataResponse = mGeoDataClient.getPlacePhotos(placeId)
photoMetadataResponse.addOnCompleteListener { task ->
// Get the list of photos
val photos = task.result
// Get the PlacePhotoMetadataBuffer (metadata for all of the photos)
val photoMetadataBuffer = photos.photoMetadata
// Get the first photo in the list
for (photo in photoMetadataBuffer) {
// Get the attribution text
val attribution = photo.attributions
}
}
发布于 2018-06-04 04:54:43
你不能。看一下PlacePhotoMetadata
的文档。有一些方法可以下载图像的位图,但没有任何方法可以返回URL。
为了得到照片,你应该这样做:
// this is your for-loop:
photoMetadataBuffer.forEach { photo ->
photo.getPhoto(client).setResultCallback({ result ->
// do whatever you want here:
showPhotoWithAttribution(photo.attributions, result.getBitmap())
})
}
请注意,将for
-loop替换为forEach
调用并没有真正的好处,它只会让您的代码看起来更整洁。
https://stackoverflow.com/questions/50668096
复制相似问题