What I want to do: I want to setup some routes overlay on google map in android !
What I have done so far: I have parsed the file (geo points) and have them ! I am using asynctask. My overlay class has a custom draw method. I have used destroyDrawingCache () in my draw function.
Problems I faced: While running the app, it gets size exceed error. I can see that the heap size is about 12mb at the time of the error.
Can anyone please help me out ? Thanks!
/////////////////////////////Error Message/////////////////////////////
10-11 19:23:02.059: ERROR/AndroidRuntime(483): FATAL EXCEPTION: main
10-11 19:23:02.059: ERROR/AndroidRuntime(483): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.graphics.Bitmap.nativeCreate(Native Method)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at com.google.android.maps.StreetViewRenderer.generateNewTileImage(StreetViewRenderer.java:120)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at com.google.android.maps.StreetViewRenderer.renderTile(StreetViewRenderer.java:88)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at com.google.android.maps.AndroidTileOverlayRenderer.renderTile(AndroidTileOverlayRenderer.java:62)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at com.google.googlenav.map.Map.drawTile(Unknown Source)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at com.google.googlenav.map.Map.drawMapBackground(Unknown Source)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at com.google.googlenav.map.Map.drawMap(Unknown Source)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at com.google.android.maps.MapView.drawMap(MapView.java:1048)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at com.google.android.maps.MapView.onDraw(MapView.java:486)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.view.View.draw(View.java:6740)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.view.V开发者_C百科iewGroup.drawChild(ViewGroup.java:1638)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.view.View.draw(View.java:6743)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.widget.FrameLayout.draw(FrameLayout.java:352)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.view.View.draw(View.java:6743)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.widget.FrameLayout.draw(FrameLayout.java:352)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1842)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.view.ViewRoot.draw(ViewRoot.java:1407)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.view.ViewRoot.performTraversals(ViewRoot.java:1163)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.os.Handler.dispatchMessage(Handler.java:99)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.os.Looper.loop(Looper.java:123)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at java.lang.reflect.Method.invokeNative(Native Method)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at java.lang.reflect.Method.invoke(Method.java:521)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-11 19:23:02.059: ERROR/AndroidRuntime(483): at dalvik.system.NativeStart.main(Native Method)
/////////////////////////////////////////////////////////////
the draw code :
public void draw(Canvas canvas, MapView mapv, boolean shadow){
BusLoc.myMapView.destroyDrawingCache ();
super.draw(canvas, mapv, shadow);
Paint mPaint = new Paint();
mPaint.setDither(true);
mPaint.setColor(Color.RED);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(2);
//ah1[0][0]=35767138;
//ah1[0][1]=-78695548;
//ah1[1][0]=35787497;
//ah1[1][1]=-78667474;
Log.d("MyOverlay","OnDraw");
int in=0;
for(in=0;in<ind-1;in++)
{
if (ah1[in][0] ==0 ||(ah1[in+1][0]==0)) break;
if((ah1[in][0] !=0) &&(ah1[in+1][0]!=0))
{
GeoPoint gP1 = new GeoPoint((int)(ah1[in][0]*1e6),(int)(ah1[in][1]*1e6));
GeoPoint gP2 = new GeoPoint((int)(ah1[in+1][0]*1e6),(int)(ah1[in+1][1]*1e6));
Point p1 = new Point();
Point p2 = new Point();
Path path = new Path();
Projection projection = BusLoc.myMapView.getProjection();
projection.toPixels(gP1, p1);
projection.toPixels(gP2, p2);
path.moveTo(p2.x, p2.y);
path.lineTo(p1.x,p1.y);
canvas.drawPath(path, mPaint);
Log.d("MyOverlay","drawn: "+gP1.toString()+":"+gP2.toString());
}
}
BusLoc.myMapView.destroyDrawingCache ();
}
精彩评论