Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix custom size of Google Maps marker in Android

How do I set the marker size. Can anyone tell me?

See This Image

like image 650
Darshan Khatri Avatar asked Jan 06 '17 16:01

Darshan Khatri


1 Answers

It's happening because the icon you are using as a marker is bigger in size.So,You can first convert it into Bitmap and change its size and then use that bitmap in as a custom marker. For example I have made a method which resizes your bitmap and returns the resized bitmap.

public Bitmap resizeBitmap(String drawableName,int width, int height){
    Bitmap imageBitmap = BitmapFactory.decodeResource(getResources(),getResources().getIdentifier(drawableName, "drawable", getPackageName()));
    return Bitmap.createScaledBitmap(imageBitmap, width, height, false);
}

Then call this method in googleMap.addMarker()

googleMap.addMarker(new MarkerOptions()
            .title("New Marker").position(yourGivenPosition).icon(BitmapDescriptorFactory.fromBitmap(resizeBitmap("your drawable name",72,64))));
like image 191
Fahim Al Mahmud Ashik Avatar answered Oct 15 '22 02:10

Fahim Al Mahmud Ashik