Change marker size in Google Maps API v2

后端 未结 5 2130
故里飘歌
故里飘歌 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:55

    Just a quick snippet that works for me:

    private Bitmap scaleImage(Resources res, int id, int lessSideSize) {
        Bitmap b = null;
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
    
        BitmapFactory.decodeResource(res, id, o);
    
        float sc = 0.0f;
        int scale = 1;
        // if image height is greater than width
        if (o.outHeight > o.outWidth) {
            sc = o.outHeight / lessSideSize;
            scale = Math.round(sc);
        }
        // if image width is greater than height
        else {
            sc = o.outWidth / lessSideSize;
            scale = Math.round(sc);
        }
    
        // Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        b = BitmapFactory.decodeResource(res, id, o2);
        return b;
    }
    

提交回复
热议问题