我正在使用googlemap-android-api v2,并希望在运行时从位图创建标记。所以我做了以下操作:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);
//create the thumbnail to use as marker
Bitmap thumbnail = ThumbnailUtils.extractThumbnail(bitmap,10,10);
MarkerOptions markerOptions = new MarkerOptions().position(currentLatLng).icon(BitmapDescriptorFactory.fromBitmap(thumbnail));
mMap.addMarker(markerOptions)
似乎不起作用,我确定
bitmap
和thumbnail
都不为空。如果我使用.fromResource(R.drawable.some_image)
而不是.fromBitmap
,它就会显示。但是,正如我所说,我想在运行时根据用户的输入进行更改。有什么提示吗?谢谢
更新:
如果我将其添加(即使用上面的代码)到托管地图的Activity / Fragment的
onResume()
中,则标记确实会显示。在用户浏览文件以获取filePath
之后,在onActivityResult()
中使用此代码之前。对我来说,这仍然很奇怪,因为onActivityResult()
在UI线程上。无论如何,能工作就好。