Change marker size in Google Maps API v2

后端 未结 5 2122
故里飘歌
故里飘歌 2020-12-05 09:59

I\'m trying to port my app to the brand new Google Maps API v2, but can\'t find how to change the size of the marker (some of my markers are smaller than default).

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 10:46

    Best solution I've found is to resize the Bitmap just before adding it as a Marker. For example, in my code I use a LevelListDrawable which references several multiple-resolution Drawables. Since I want half-size Markers, I do:

    LevelListDrawable d=(LevelListDrawable) getResources().getDrawable(R.drawable.estado_variable);
    d.setLevel(1234);
    BitmapDrawable bd=(BitmapDrawable) d.getCurrent();
    Bitmap b=bd.getBitmap();
    Bitmap bhalfsize=Bitmap.createScaledBitmap(b, b.getWidth()/2,b.getHeight()/2, false);
    mapa.addMarker(new MarkerOptions()
            .position(POSITION)
            .title("Title")
            .icon(BitmapDescriptorFactory.fromBitmap(bhalfsize))
            );
    

    This way, I can keep using Drawables while been able to obtain differently sized markers just converting them to Bitmap and resizing as needed.

提交回复
热议问题