将MapView设置为特定宽度和高度后的Google API MapView OutOfMemory

时间:2011-05-30 12:48:21

标签: android android-mapview out-of-memory

我搜索了这个问题,我发现了一些有关相同的stackoverflow问题,但不知道如何解决问题。

我创建了一个活动,我想添加一个非常小的mapview(如140w X 70h)。它只是展示了这个地方的小预览。当您点击这个小地图视图时,您会获得一个带有空洞地图的新活动。

MapView的:

<com.google.android.maps.MapView android:id="@+id/mapview" 
                android:layout_width="140dip"
                android:layout_height="80dip"
                android:layout_below="@id/attributes"
                android:layout_alignParentRight="true"
                android:apiKey="****"
                android:paddingBottom="60dp"/>

logcat的:

05-30 14:34:53.758: ERROR/dalvikvm(1608): Out of memory: Heap Size=4039KB,   Allocated=2768KB, Bitmap Size=625KB
05-30 14:34:53.758: DEBUG/AndroidRuntime(1608): Shutting down VM
05-30 14:34:53.758: WARN/dalvikvm(1608): threadid=1: thread exiting with uncaught exception (group=0x400259f8)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): FATAL EXCEPTION: main
05-30 14:34:53.768: ERROR/AndroidRuntime(1608): java.lang.OutOfMemoryError
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at com.google.googlenav.map.Map.resize(Unknown Source)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at com.google.android.maps.MapView.onMeasure(MapView.java:554)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.view.View.measure(View.java:8172)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:578)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:362)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.view.View.measure(View.java:8172)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:989)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.widget.ScrollView.onMeasure(ScrollView.java:286)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.view.View.measure(View.java:8172)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:578)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:362)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.view.View.measure(View.java:8172)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.view.View.measure(View.java:8172)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.view.View.measure(View.java:8172)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.view.ViewRoot.performTraversals(ViewRoot.java:805)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1744)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.os.Looper.loop(Looper.java:144)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at android.app.ActivityThread.main(ActivityThread.java:4937)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at java.lang.reflect.Method.invokeNative(Native Method)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at java.lang.reflect.Method.invoke(Method.java:521)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-30 14:34:53.768: ERROR/AndroidRuntime(1608):     at dalvik.system.NativeStart.main(Native Method)

这是错误。当我使用fill_parent时它可以工作,但我不想要一个带有fill_parent的mapview。

也许你们知道另一种方法来获取地图上当前(或给定)位置的预览小图像作为图像。 是不是可以显示一个小的mapview?

谢谢

1 个答案:

答案 0 :(得分:3)

如果您只想在没有互动的情况下展示静态地图,我建议您使用谷歌的static map api。您可以定义标记,中心,大小和一些标签,并返回生成的图像,可以在ImageView中轻松显示。这样做的好处是:您不必为一个小的地图图像调用完整的MapView。没有内存或用户交互的开销。适合你的情景。