I have used 5 markers in google map android and every 5 secs marker position also changed with animation. in this case, I want to do resize the icons dynamically based on the zoom level.
I have used 5 markers in google map android and every 5 secs marker position also changed with animation. in this case, I want to do resize the icons dynamically based on the zoom level.
Just try with below code snippet, It is used foe me. This method will return the image which is appropriate to your zoom level and your expected height as well as width.
public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
return Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
}
You can do it by creating bitmap with custom height
int height = 100;// resize according to your zooming level
int width = 100;// resize according to your zooming level
BitmapDrawable bitmapdraw = (BitmapDrawable)getResources().getDrawable(R.mipmap.marker);
Bitmap b=bitmapdraw.getBitmap();
Bitmap finalMarker= Bitmap.createScaledBitmap(b, width, height, false);
And add this bitmap on map.
map.addMarker(new MarkerOptions()
.position(POSITION)
.title("Your title")
.icon(BitmapDescriptorFactory.fromBitmap(finalMarker))
);
Hope this works!