Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not understanding drawAt() method for com.google.android.maps.Overlay

Trying to make an google maps overlay in an android program. Inside of my overlay's draw method, I have two ways of adding a pin. One of them works, and one does not. Unfortunately, the one that does not work is also the only one that has the ability to add a shadow! Any help?

@Override
public void draw(android.graphics.Canvas canvas, MapView mapView,
        boolean shadow) {

    Point po = mapView.getProjection().toPixels(mapView.getMapCenter(),
            null);

    // This does _not_ work, but I would really like it to!
    drawAt(canvas, mapView.getResources().getDrawable(R.drawable.map_marker_v),
           po.x, po.y, false);

    // This does work, but only does half the job
    canvas.drawBitmap(BitmapFactory.decodeResource(mapView.getResources(),
            R.drawable.map_marker_v), po.x, po.y, null);


}

Edit: fixed type

like image 600
Hamy Avatar asked Jul 09 '26 05:07

Hamy


1 Answers

I think your problem may simply be that you haven't set the bounds on the drawable in drawAt(). You can either manually set the bounds using Drawable.setBounds(), or you can use ItemizedOverlay's convenience methods boundCenter() or boundCenterBottom().

I believe the reason the second method works is because with a decoded Bitmap you don't have to specify the bounds of the Drawable.

like image 141
Dan Lew Avatar answered Jul 11 '26 20:07

Dan Lew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!