Android maps out of memory error

Posted by SamB09 on Stack Overflow See other posts from Stack Overflow or by SamB09
Published on 2010-03-15T19:02:06Z Indexed on 2010/03/15 20:39 UTC
Read the original article Hit count: 320

Filed under:

Hi , sometimes when running a google maps program with an overlay image i will receive a bit map out of memory error. It always seems to be at a random point in the app. Im not sure how to solve this. Anyone have any ideas ? My overlay code is below , im not sure if you need to see the class its called in though?

public class MyOverlay2 extends Overlay {

private static final double MAX_TAP_DISTANCE_KM = 3;  
  // Rough approximation - one degree = 50 nautical miles  
  private static final double MAX_TAP_DISTANCE_DEGREES = MAX_TAP_DISTANCE_KM * 0.5399568 * 50;  
  private final GeoPoint gPoint;  
  private final Context cont;  
  private final int draw;  
//  private final int lat;



  public MyOverlay2(Context cont, GeoPoint gPoint1, int draw) {  // constructor will be called in the userLocation class to draw an overly image
    this.cont = cont;  
    this.gPoint = gPoint1;  
    this.draw = draw;  
  }  



@Override  
  public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {  // constructor takes 3 arguments
    super.draw(canvas, mapView, shadow);  

    // Convert geo coordinates to screen pixels  
    Point screenPoint = new Point();  
    mapView.getProjection().toPixels(gPoint, screenPoint);  

//Read the image from the xml resource using a bitmap factory

    BitmapFactory.Options options=new BitmapFactory.Options(); 
    options.inSampleSize = 1; Bitmap preview_bitmap=BitmapFactory.decodeResource(cont.getResources(),R.drawable.monday12,options);


  //draw the image at the location specified by the co-ordinates
         canvas.drawBitmap(preview_bitmap,    screenPoint.x - preview_bitmap.getWidth() /2,  
                 screenPoint.y - preview_bitmap.getHeight()/2 , null);   // get the images height and width values divided by two draw the image at the specified screen points
    return true;  
  }  

  @Override  
  public boolean onTap(GeoPoint s, MapView mapView) {  
    // Handle tapping on the overlay here  
    return true;  
  }  

}

© Stack Overflow or respective owner

Related posts about android