[英]How to fix custom size of Google Maps marker in Android
It's happening because the icon you are using as a marker is bigger in size.So,You can first convert it into Bitmap and change its size and then use that bitmap in as a custom marker. 之所以发生这种情况,是因为您用作标记的图标尺寸较大。因此,您可以先将其转换为位图并更改其大小,然后将该位图用作自定义标记。 For example I have made a method which resizes your bitmap and returns the resized bitmap.
例如,我已经制作了一个调整位图大小并返回调整大小的位图的方法。
public Bitmap resizeBitmap(String drawableName,int width, int height){
Bitmap imageBitmap = BitmapFactory.decodeResource(getResources(),getResources().getIdentifier(drawableName, "drawable", getPackageName()));
return Bitmap.createScaledBitmap(imageBitmap, width, height, false);
}
Then call this method in googleMap.addMarker()
然后在
googleMap.addMarker()
调用此方法
googleMap.addMarker(new MarkerOptions()
.title("New Marker").position(yourGivenPosition).icon(BitmapDescriptorFactory.fromBitmap(resizeBitmap("your drawable name",72,64))));
更改标记图像(图标)的尺寸,30 x 40我认为没问题
I assume you have a bmp
image since you are setting a custom marker. 我假设您有一个
bmp
图像,因为您正在设置自定义标记。 To resize the bmp
, use Bitmap.createScaledBitmap (Bitmap src, int width, int height, boolean filter)
要调整
bmp
大小,请使用Bitmap.createScaledBitmap (Bitmap src, int width, int height, boolean filter)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.