How to specify the size of the icon on the Marker

2019-01-23 03:38发布

In may app i use Map from Google Maps V2 and in this map i am trying to add markers each Marker with an icon, but the marker is taking the size of the icon which is making the icon looks flue. How can i specify the size of the marker in dp so that i can control how it looks like on the map

3条回答
甜甜的少女心
2楼-- · 2019-01-23 03:50

Currently i think we cannot change the marker size, so u can add marker image in drawable and re-size something like this:,

int height = 100;
 int width = 100;
 BitmapDrawable bitmapdraw=(BitmapDrawable)getResources().getDrawable(R.mipmap.marker);
  Bitmap b=bitmapdraw.getBitmap();
Bitmap smallMarker = Bitmap.createScaledBitmap(b, width, height, false);

Ur add marker be like this with icon

                map.addMarker(new MarkerOptions()
                        .position(POSITION)
                        .title("Your title")
                        .icon(BitmapDescriptorFactory.fromBitmap(smallMarker))
                );
查看更多
爷、活的狠高调
3楼-- · 2019-01-23 03:53

I think you can look for an answer on this question, where it already explained how to create a custom marker, with a given width and height by creating a dynamic bitmap.

查看更多
我命由我不由天
4楼-- · 2019-01-23 03:58

[edit: formatting]

Drawable circleDrawable = getResources().getDrawable(R.mipmap.primarysplitter);
            bitmapDescriptor=getMarkerIconFromDrawable(circleDrawable);


private BitmapDescriptor getMarkerIconFromDrawable(Drawable drawable) {
    Canvas canvas = new Canvas();
    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    canvas.setBitmap(bitmap);
    drawable.setBounds(0, 0, (int)getResources().getDimension(R.dimen._30sdp), (int)getResources().getDimension(R.dimen._30sdp));
    drawable.draw(canvas);
    return BitmapDescriptorFactory.fromBitmap(bitmap);
}
查看更多
登录 后发表回答