How to specify the size of the icon on the Marker in Google Maps V2 Android

前端 未结 5 671
温柔的废话
温柔的废话 2020-12-08 13:32

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 t

5条回答
  •  一个人的身影
    2020-12-08 14:11

    Currently it's not possible to specify a marker size using MarkerOptions, so your only option is to rescale your Bitmap before setting it as your marker icon.

    Creating the scaled Bitmap:

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

    Using smallMarker as the marker icon:

    map.addMarker(new MarkerOptions()
            .position(POSITION)
            .title("Your title")
            .icon(BitmapDescriptorFactory.fromBitmap(smallMarker))
    );
    

提交回复
热议问题