我正在使用googlemap-android-api v2,並希望在運行時從位圖創建標記。所以,我做的:android,在googlemap上從位圖添加標記
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
不爲空。如果不是.fromBitmap
,那麼我使用.fromResource(R.drawable.some_image)
然後顯示。但是,正如我所說的,我想在用戶輸入的運行時進行更改。
任何提示?感謝
更新: 標記它只表示如果我在活動/片段承載地圖的onResume()
添加它(即,使用上面的代碼)。在我使用此代碼之前,在onActivityResult()
之後,用戶瀏覽文件以獲得filePath
。對我來說,由於onActivityResult()
在UI線程上,所以它仍然很奇怪。無論如何,無論什麼作品。
嗨,你有沒有嘗試改變extractThumbnail中的值? 10,10它很小。 – HoodVinci
是的,沒有工作。 –