简体   繁体   English

如何在Android的Google Maps API v3中更改标记大小?

[英]How to change marker size in Google Maps API v3 with Android?

I have added a few markers on my map but when I run my app, I see the markers to be very small. 我在地图上添加了一些标记,但是当我运行应用程序时,看到的标记很小。 I have created a custom icon with the mdpi , hdpi , xhdpi and xxhdpi dimensions but I still see them small. 我使用mdpihdpixhdpixxhdpi尺寸创建了一个自定义图标,但是我仍然看到它们很小。

This is how add the markers to the map: 这是将标记添加到地图的方法:

LatLng latLng = new LatLng(lat, lng);
MarkerOptions markerOptions = new MarkerOptions().position(latLng).title("My Marker");
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.my_pin));
Marker marker = googleMap.addMarker(markerOptions);

And this is how my map looks like: 这就是我的地图的样子:

在此处输入图片说明

And this is what I want to achieve: 这就是我想要实现的目标:

在此处输入图片说明

How to change marker size a little bit to be more visible? 如何稍微改变标记大小以使其更明显?

I use Gimp and the extension Script Fu Save Android icons to create all my mipmap or icons in my apps. 我使用Gimp和扩展脚本Fu Save Android 图标在应用程序中创建我的所有mipmap图标

After install the script, you get this menu in the menu bar: 安装脚本后,您会在菜单栏中得到以下菜单:

GIMP的屏幕截图

After click on "Save Android Icons...", you'll get this window: 点击“保存Android图标...”后,您将获得以下窗口:

保存图标的窗口的屏幕截图

The extension exports all icons according with Android Icon's Sizes: 该扩展程序根据Android图标的大小导出所有图标:

文件夹的屏幕截图

After generate all icons, just move them to your project folder 生成所有图标后,只需将它们移动到您的项目文件夹

try this if hope it will help you if not tell me to delete the answer ...! 如果希望,如果不告诉我删除答案,请尝试此操作...!

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 然后

googleMap.addMarker(new MarkerOptions()
        .title("New Marker").position(yourGivenPosition).icon(BitmapDescriptorFactory.fromBitmap(resizeBitmap("your drawable name",72,64))));

First, choose the larger image and make an image asset for all sizes. 首先,选择较大的图像并制作所有尺寸的图像资产。 For that Right click on the drawable folder and select new -> Image Asset -> select appropriate options and select image. 为此,右键单击可绘制文件夹,然后选择新建->图像资产->选择适当的选项,然后选择图像。 finish and it will automatically create all size of images. 完成,它将自动创建所有尺寸的图像。 Use this image as the marker. 将此图像用作标记。

So, now at the end, you have the only solution is that use large size image into the marker. 因此,最后,您唯一的解决方案是将大尺寸图像用作标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM