在Google Maps API v2中更改标记大小 [英] Change marker size in Google Maps API v2

查看:78
本文介绍了在Google Maps API v2中更改标记大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的应用程序移植到全新的Google Maps API v2,但找不到如何更改标记的大小(我的一些标记小于默认值).

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

在v1中,我使用了Drawable,并在将其添加到地图之前用setBounds()对其进行了缩放.

In v1, I used a Drawable which I scaled with setBounds() before adding it to the map.

但是现在,在v2中,我不能使用Drawable.我必须使用MarkerOptions().icon(),它只需一个BitmapDescriptor(由BitmapDescriptorFactory生成).

But now, in v2, I can't use a Drawable. I've to use MarkerOptions().icon(), which takes just a BitmapDescriptor (generated with a BitmapDescriptorFactory).

看参考文献,似乎不支持设置或更改BitmapDescriptor大小.

Looking at the reference, there doesn't seem to be any support for setting or changing the BitmapDescriptor size.

那么,我是否错过了一些东西,还是根本无法在此API版本中设置自定义标记的大小?

So, have I missed something, or is it just plain impossible to set the size for custom markers in this API version?

推荐答案

您可以先将其转换为位图并更改其大小,然后将该位图用作自定义标记.例如,我首先创建了一个方法,该方法接受可绘制文件夹中图像文件的名称以及要设置的标记的宽度和高度.

You can first convert it into Bitmap and change its size and then use that bitmap in as a custom marker. For example I first created a method which accepts name of your image file in drawable folder, and width and height of marker you want to set.

public Bitmap resizeMapIcons(String iconName,int width, int height){
    Bitmap imageBitmap = BitmapFactory.decodeResource(getResources(),getResources().getIdentifier(iconName, "drawable", getPackageName()));
    Bitmap resizedBitmap = Bitmap.createScaledBitmap(imageBitmap, width, height, false);
    return resizedBitmap;
}

然后在setUpMap()方法中这样调用以创建所需大小的新标记.

Then call like this in setUpMap() method to create a new marker of required size.

googleMap.addMarker(new MarkerOptions()
            .title("New Marker")
            .snippet("Check out this place.")
            .position(chelsea).icon(BitmapDescriptorFactory.fromBitmap(resizeMapIcons("image_name",100,100))));

这篇关于在Google Maps API v2中更改标记大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆