简体   繁体   English

如何在Android中修复Google地图标记的自定义尺寸

[英]How to fix custom size of Google Maps marker in Android

How do I set the marker size. 如何设置标记大小。 Can anyone tell me? 有人能告诉我吗?

见此图片

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.

相关问题 如何为Android Google Maps v2调整自定义标记图标的大小? - How to size custom marker icons for Android Google Maps v2? Google Maps自定义标记图标大小未保留在Android上 - Google Maps custom marker icon size not preserved on Android 动态增加Google地图中自定义标记的大小-Android - Dynamically increase the size of custom marker in google maps - Android android中谷歌地图中的自定义标记 - Custom marker in google maps in android Google Maps Custom Marker Android - Google maps custom marker android 我如何使Google地图不更改标记的自定义图标大小? - How I make that google maps not change the custom icons size of marker? 动态增加Google地图中自定义标记的大小 - Dynamically increase the size of custom marker in google maps 如何在Google Maps V2 Android 中指定Marker 上图标的大小 - How to specify the size of the icon on the Marker in Google Maps V2 Android 如何在Android的Google Maps API v3中更改标记大小? - How to change marker size in Google Maps API v3 with Android? ANDROID:如何在Google地图上为标记制作自定义视图(布局) - ANDROID: How make custom view(layout) for marker on Google Maps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM