简体   繁体   中英

How to fix custom size of Google Maps marker in Android

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

见此图片

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))));

更改标记图像(图标)的尺寸,30 x 40我认为没问题

I assume you have a bmp image since you are setting a custom marker. To resize the bmp , use Bitmap.createScaledBitmap (Bitmap src, int width, int height, boolean filter)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM