How to scale markers on Android and properly configure shadow and onTap

I scale markers in MapView with the following code

OverlayItem oi = new OverlayItem(point,"Title", "Desc");
oi.setMarker(getCustomMarker(0.5f, 0.5f));
itemizedOverlay.addOverlay(oi);

and

private BitmapDrawable getCustomMarker(float scaleWidth, float scaleHeight){
    int width = originalMarker.getWidth();
    int height = originalMarker.getHeight();

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap bitmap = Bitmap.createBitmap(originalMarker, 0, 0, width, height, matrix, true);

    BitmapDrawable bm = new BitmapDrawable(bitmap);
    bm.setBounds(0,0,bitmap.getWidth(),bitmap.getHeight());

    return bm;
}

which works, but the shadow below the marker has the wrong offset when scaling. Also; I override public boolean onTap(int index)in ItemizedOverlay to detect marker taps, but this seems inaccurate. I can click some range outside the marker and still run onTap ...

+3
source share
1 answer

I use this to set the shadow

int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
drawable.setBounds(-w / 2, -h, w / 2, 0);
+1
source

Source: https://habr.com/ru/post/1723154/


All Articles