【发布时间】:2021-08-12 09:04:25
【问题描述】:
我正在尝试将我拥有的 ImageVector 图标(例如,创建为 Icons.Default.Home)添加到 Google 地图中的标记。我目前拥有的是这样的:
val opt = MarkerOptions()
opt.position(LatLng(lat, lng)) // lat and lng are defined above
opt.title(title) // title as well
opt.icon(BitmapDescriptorFactory.?????) // and there the problem occurs.
我发现BitmapDescriptorFactory 可以通过传递资源或位图(分别为BitmapDescriptorFactory.fromResource(resourceId: Int) 和BitmapDescriptorFactory.fromBitmap(image: Bitmap))来创建请求的BitmapDescriptor。
问题是我不知道如何将我从Icons.Default.Home 获得的 ImageVector 转换为上述任何一种。我在堆栈上发现了一些关于将可绘制矢量转换为位图的问题,但仍然没有一个涵盖转换 ImageVector 的问题。我还检查了 ImageVector 的实例是否有任何可能有用的方法,但它只能 - 如果我没记错的话 - 将其转换为字符串,这在我的情况下完全没用。
我们将不胜感激任何帮助
【问题讨论】:
标签: android google-maps android-jetpack android-jetpack-compose