2013-09-24 27 views
2

我正在使用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) 

它似乎從來沒有工作,我敢肯定,這兩個bitmapthumbnail不爲空。如果不是.fromBitmap,那麼我使用.fromResource(R.drawable.some_image)然後顯示。但是,正如我所說的,我想在用戶輸入的運行時進行更改。

任何提示?感謝

更新: 標記它只表示如果我在活動/片段承載地圖的onResume()添加它(即,使用上面的代碼)。在我使用此代碼之前,在onActivityResult()之後,用戶瀏覽文件以獲得filePath。對我來說,由於onActivityResult()在UI線程上,所以它仍然很奇怪。無論如何,無論什麼作品。

+0

嗨,你有沒有嘗試改變extractThumbnail中的值? 10,10它很小。 – HoodVinci

+0

是的,沒有工作。 –

回答

0

我做同樣的這個像下面

首先,我創建一個路徑上運行時

Drawable drawable = Drawable.createFromPath(filePath); 

然後被拉伸,我只是將它添加到標記這樣

mMap.addMarker(new MarkerOptions() 
      .position(location) 
      .title(title) 
      .icon(BitmapDescriptorFactory.fromBitmap(((BitmapDrawable)drawable).getBitmap()))); 

我希望能幫助到你。

+0

tks分享。它仍然不顯示。 LogCat顯示'ERROR/GooglePlayServicesUtil(5951):未找到Google Play服務資源。檢查你的項目配置,確保包含資源。'我的地圖和其他標記(使用'fromResource'創建)顯示,所以我不知道錯誤的含義。 –

+0

什麼是文件路徑?它是服務器上的本地文件還是文件? – Sharj

+0

tks後續,這是一個本地文件。其實我找到了它並更新了我的帖子。 –

相關問題