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

前端 未结 5 670
温柔的废话
温柔的废话 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:27

    The accepted answer is outdated (Resources::getDrawable has been deprecated since API level 22). Here's an updated version:

    int height = 100;
    int width = 100;
    Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable. marker);
    Bitmap smallMarker = Bitmap.createScaledBitmap(b, width, height, false);
    BitmapDescriptor smallMarkerIcon = BitmapDescriptorFactory.fromBitmap(smallMarker);
    

    and then apply it in MarkerOption

    .icon(smallMarkerIcon)
    

提交回复
热议问题