简体   繁体   English

如何在 Jetpack Compose 中将图像 url 加载到谷歌 map 标记图标

[英]How can I load image url to google map marker icon in Jetpack Compose

I get the image URL from the server and I want to load the URL in the Google Maps marker icon.我从服务器获得图像 URL,我想在 Google 地图标记图标中加载 URL。 How can I do this?我怎样才能做到这一点?

using Glide Library使用 Glide 库

fun loadIcon(
    context: Context,
    url: String?,
    placeHolder: Int,
): BitmapDescriptor? {
    try {
        var bitmap: Bitmap? = null
        Glide.with(context)
            .asBitmap()
            .load(url)
            .error(placeHolder)
            // to show a default icon in case of any errors
            .into(object : CustomTarget<Bitmap>() {
                override fun onResourceReady(
                    resource: Bitmap,
                    transition: Transition<in Bitmap>?
                ) {

                    bitmap = resource

                }

                override fun onLoadCleared(placeholder: Drawable?) {

                }
            })
        return BitmapDescriptorFactory.fromBitmap(bitmap!!)
    } catch (e: Exception) {
        e.printStackTrace()
        return null
    }

}

then call然后打电话

 var bitmap = loadIcon(context, item.icon, R.drawable.placeholder_image,)
                    Marker(
                        state = MarkerState(
                            position = LatLng(
                                item.lat.toDouble(),
                                item.long.toDouble()
                            )
                        ),
                        title = item.name,
                        icon = bitmap,
                        )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM