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.
Asked
Active
Viewed 1,790 times
3
-
post your code with what you have tried. – karan Dec 21 '18 at 12:39
-
Possible duplicate of [How to specify the size of the icon on the Marker in Google Maps V2 Android](https://stackoverflow.com/questions/35718103/how-to-specify-the-size-of-the-icon-on-the-marker-in-google-maps-v2-android) – Jaswant Singh Dec 21 '18 at 12:50
2 Answers
2
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);
}

ssowri1
- 1,299
- 2
- 14
- 31
0
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!

ppreetikaa
- 1,149
- 2
- 15
- 22