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

问题描述

我想端口我的应用程序,以全新的谷歌地图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 我用了一个绘制对象我缩放与的setBounds()将其添加到地图前。但现在,在 V2 ,我不能使用绘制对象,我已经用 MarkerOptions()图标(),它只需一个 BitMapDesc​​riptor(带BitmapDesc​​riptorFactory生成)。

In v1 I used a Drawable which I scaled with setBounds() before adding it to the map. But now, in v2, I can't use a Drawable, I've to useMarkerOptions().icon(), which takes just a BitMapDescriptor (generated with a BitmapDescriptorFactory).

综观参考,似乎没有要设置或更改 BitmapDesc​​riptor 尺寸的支持。

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

所以,我错过了一些东西,或者是它只是普通的不能设置标记大小定制标记在这个版本的API?

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

推荐答案

最好的解决办法,我发现是调整位图之前将其添加为标记。例如,在我的code我用的是 LevelListDrawable 它引用几个多分辨率绘制对象秒。因为我想一半大小的标记,我做的:

Best solution I've found is to resize the Bitmap just before adding it as a Marker. For example, in my code I use a LevelListDrawable which references several multiple-resolution Drawables. Since I want half-size Markers, I do:

LevelListDrawable d=(LevelListDrawable) getResources().getDrawable(R.drawable.estado_variable);
d.setLevel(1234);
BitmapDrawable bd=(BitmapDrawable) d.getCurrent();
Bitmap b=bd.getBitmap();
Bitmap bhalfsize=Bitmap.createScaledBitmap(b, b.getWidth()/2,b.getHeight()/2, false);
mapa.addMarker(new MarkerOptions()
        .position(POSITION)
        .title("Title")
        .icon(BitmapDescriptorFactory.fromBitmap(bhalfsize))
        );

这样一来,我可以继续使用可绘制,同时能够获得不同大小的标志物只是将它们转换为位图和调整需要。

This way, I can keep using Drawables while been able to obtain differently sized markers just converting them to Bitmap and resizing as needed.

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

08-02 01:49