开发者

Google API MapView OutOfMemory after setting the MapView to specific width and height

i searched for this Problem, and i found some stackoverflow Questions about the same but without any idea how to resolve the problem.

I created an activity and i want to add a really small mapview (like 140w X 70h). It is only to show a small preview of where the place is. When you click this little mapview you get a new inflate to a new activity with the hole map.

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)

this is the error. When i use fill_parent it works, but i dont want a mapview with fill_parent.

Maybe you guys know another way to get a preview small image of the current (or given) position on the map as image. I开发者_运维知识库sn't it possible to show a small mapview ?

thanks


If you just want to show a static map without interaction I recommend the static map api from google. You can define markers, the center, the size and some labels and it returns a generated image that can be easily shown inside a ImageView. The benefit of this: You don't have to invoke a complete MapView for just a small map image. No overhead of memory or user interaction. Perfect for the scenario you have.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜