Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
228 views
in Technique[技术] by (71.8m points)

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

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 the icon looks flue. How can i specify the size of the marker in dp so that i can control how it looks like on the map

question from:https://stackoverflow.com/questions/35718103/how-to-specify-the-size-of-the-icon-on-the-marker-in-google-maps-v2-android

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...