2013-05-03 29 views
0

我試圖在谷歌地圖上畫一張圖片。我正在使用最新版本的谷歌播放服務,並檢查了很多這個問題,並找不到答案。內存不足例外 - 谷歌地圖GroundOverLay

下面是一些代碼:

BitmapDescriptor image = BitmapDescriptorFactory.fromResource(R.drawable.drawing_bg); 
    LatLngBounds drawingBounds = new LatLngBounds(
            new LatLng(29.93530, 30.88324), 
            new LatLng(29.93609, 30.88329)) 
           .including(new LatLng(29.93580, 30.88286)) 
           .including(new LatLng(29.93563, 30.88374)) 
           .including(new LatLng(29.93593, 30.88347)) 
           .including(new LatLng(29.93561, 30.88298)) 
           .including(new LatLng(29.93591, 30.88344)) 
           .including(new LatLng(29.93563, 30.88301)); 
    GroundOverlay groundOverlay = mMap.addGroundOverlay(new GroundOverlayOptions() 
    .image(image) 
    .zIndex(2) 

    .positionFromBounds(drawingBounds) 
    .transparency((float) 0.0)); 

    final Marker currentLocationMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(29.93530, 30.88324)).draggable(true)); 
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(29.935431502437588,30.88327579200268), 20)); 

從logcat的:

05-03 11:45:17.860: E/dalvikvm-heap(1115): Out of memory on a 67108880-byte allocation. 
    05-03 11:45:17.860: I/dalvikvm(1115): "GLThread 8598" prio=5 tid=21 RUNNABLE 
    05-03 11:45:17.860: I/dalvikvm(1115): | group="main" sCount=0 dsCount=0 obj=0x4284d580 self=0x5a559790 
    05-03 11:45:17.860: I/dalvikvm(1115): | sysTid=1502 nice=1 sched=0/0 cgrp=apps handle=1596223616 
    05-03 11:45:17.860: I/dalvikvm(1115): | schedstat=(216011094 92043700 221) utm=19 stm=2 core=3 
    05-03 11:45:17.860: I/dalvikvm(1115): at android.graphics.Bitmap.nativeCreate(Native Method) 
    05-03 11:45:17.860: I/dalvikvm(1115): at android.graphics.Bitmap.createBitmap(Bitmap.java:640) 
    05-03 11:45:17.860: I/dalvikvm(1115): at android.graphics.Bitmap.createBitmap(Bitmap.java:620) 
    05-03 11:45:17.860: I/dalvikvm(1115): at maps.s.h.a((null):-1) 
    05-03 11:45:17.860: I/dalvikvm(1115): at maps.cr.a.a((null):-1) 
    05-03 11:45:17.860: I/dalvikvm(1115): at maps.cr.a.a((null):-1) 
    05-03 11:45:17.860: I/dalvikvm(1115): at maps.z.aa.b((null):-1) 
    05-03 11:45:17.860: I/dalvikvm(1115): at maps.z.aa.a((null):-1) 
    05-03 11:45:17.860: I/dalvikvm(1115): at maps.z.bi.a((null):-1) 
    05-03 11:45:17.860: I/dalvikvm(1115): at maps.af.v.a((null):-1) 
    05-03 11:45:17.860: I/dalvikvm(1115): at maps.af.v.a((null):-1) 
    05-03 11:45:17.860: I/dalvikvm(1115): at maps.af.v.a((null):-1) 
    05-03 11:45:17.860: I/dalvikvm(1115): at maps.p.q.m((null):-1) 
    05-03 11:45:17.860: I/dalvikvm(1115): at maps.p.q.run((null):-1) 
    05-03 11:45:17.875: W/dalvikvm(1115): threadid=21: thread exiting with uncaught exception (group=0x412cc2a0) 
    05-03 11:45:17.880: E/AndroidRuntime(1115): FATAL EXCEPTION: GLThread 8598 
    05-03 11:45:17.880: E/AndroidRuntime(1115): java.lang.OutOfMemoryError 
    05-03 11:45:17.880: E/AndroidRuntime(1115):  at android.graphics.Bitmap.nativeCreate(Native Method) 
    05-03 11:45:17.880: E/AndroidRuntime(1115):  at android.graphics.Bitmap.createBitmap(Bitmap.java:640) 
    05-03 11:45:17.880: E/AndroidRuntime(1115):  at   android.graphics.Bitmap.createBitmap(Bitmap.java:620) 
    05-03 11:45:17.880: E/AndroidRuntime(1115):  at maps.s.h.a(Unknown Source) 
    05-03 11:45:17.880: E/AndroidRuntime(1115):  at maps.cr.a.a(Unknown Source) 
    05-03 11:45:17.880: E/AndroidRuntime(1115):  at maps.cr.a.a(Unknown Source) 
    05-03 11:45:17.880: E/AndroidRuntime(1115):  at maps.z.aa.b(Unknown Source) 
    05-03 11:45:17.880: E/AndroidRuntime(1115):  at maps.z.aa.a(Unknown Source) 
    05-03 11:45:17.880: E/AndroidRuntime(1115):  at maps.z.bi.a(Unknown Source) 
    05-03 11:45:17.880: E/AndroidRuntime(1115):  at maps.af.v.a(Unknown Source) 
    05-03 11:45:17.880: E/AndroidRuntime(1115):  at maps.af.v.a(Unknown Source) 
    05-03 11:45:17.880: E/AndroidRuntime(1115):  at maps.af.v.a(Unknown Source) 
    05-03 11:45:17.880: E/AndroidRuntime(1115):  at maps.p.q.m(Unknown Source) 
    05-03 11:45:17.880: E/AndroidRuntime(1115):  at maps.p.q.run(Unknown Source) 
    05-03 11:45:29.395: W/SurfaceView(1115): CHECK surface infomation creating=false formatChanged=false sizeChanged=false visible=false visibleChanged=true surfaceChanged=true realSizeChanged=false redrawNeeded=false left=false top=false 

我真的很感激

+0

我想你可能會遇到同樣的問題。我已經在Google Maps Android API跟蹤器上打開了一個錯誤報告:https://code.google.com/p/gmaps-api-issues/issues/detail?id=7325 – 2014-11-11 07:07:31

+0

對此的任何解決方案? – 2015-04-05 20:09:36

回答

0

你不應該使用太大的圖像進行任何幫助。你logcat建議你嘗試分配67 MB,這對於大多數設備來說太過分了。

編輯:

也許嘗試使用TileOverlay代替GroundOverlay如果你想顯示(城市,國家)在大面積的圖像,而不是把它放大像素化時。

+0

我想要使用的圖像只有663KB,分辨率是1223x1248。你能否讓我知道是否應該處理?我可以縮小圖像尺寸,但我需要最佳的放大質量。 此外,此問題發生在三星S3和東芝茁壯平板電腦上,但不是三星S3 Mini上。 – Menshawi 2013-05-03 17:49:59

+1

當放入可繪製nodpi或文件夾匹配設備密度時,1223x1248圖像的內存大約爲6MB。每個像素需要4個字節。如果它放在xhdpi設備上的mdpi文件夾中,它將在內存中擴展到24MB。我不確定這個67MB是從哪裏來的。這是你在地圖活動中唯一的代碼嗎? – 2013-05-04 10:05:19

+0

還有另一個覆蓋圖,在地圖上以編程方式繪製,並在我使用的相同圖像下。 – Menshawi 2013-05-04 16:07:40