android - 从地方api android获取照片
问题描述
private fun getPhotoAndDetail(id: String?) :Bitmap{ var bitmap:Bitmap= BitmapFactory.decodeResource(this.resources,R.drawable.common_full_open_on_phone)
val placeRequest=FetchPlaceRequest.builder(id!!, listOf(Place.Field.ADDRESS,Place.Field.PHOTO_METADATAS)).build()
placesClient.fetchPlace(placeRequest).addOnSuccessListener{ it ->
val place=it!!.place
val photoMeta= place.photoMetadatas!![0]
val photoRequest=FetchPhotoRequest.builder(photoMeta).setMaxWidth(500) // Optional.
.setMaxHeight(300).build()
placesClient.fetchPhoto(photoRequest).addOnSuccessListener{
bitmap=it.bitmap
Log.e(TAG,it.toString())
}.addOnFailureListener{
if (it is ApiException) {
var apiException = it as ApiException;
var statusCode = apiException.statusCode;
// Handle error with given status code.
Log.e(TAG, "Place not found: " + it.message)
}}.addOnFailureListener{
Log.e(TAG, "Place not found: " + it.message)
}
}
return bitmap
}
我有这个函数可以从 Places Api 返回位图。但它永远不会在获取时达到成功的侦听器。在它获取有关地点的所有数据并显示它之前。
解决方案
推荐阅读
- java - 我想使用可点击的 textView 向下滚动到文本正文
- matlab - 如何在matlab中确定随机森林中的树数?
- amazon-web-services - 每个 EC2 都需要一个公共子网吗?
- python - 无需重新加载页面即可触发瓶子功能
- javascript - JS getElementById 仅在检查元素后可见
- jquery - 解释以下 jQuery: $('h1').append($('h1 + h2'));
- javascript - Why when referring to the second field, the value is taken from the first?
- python - Python lib:未定义符号:_Py_FalseStruct
- javascript - 我可以使用哪些离线软件或实用程序来检测运行 Web 应用程序的最低 Javascript 版本?
- .net-core - 引号不在 CSV 中的值周围