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

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

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

提交回复
热议问题