小编stk*_*stk的帖子

GoogleMaps:自定义ItemizedOverlay和OverlayItem,显示不同标记的正确方法

我一直在寻找关于扩展ItemizedOverlay和OverlayItem的正确方法的清晰信息,但我得到的结果还不能满足我.简而言之,我需要在地图上显示与多个位置相关的不同类型的标记; 要显示的标记的类型由位置本身的特定属性确定.我还需要在选择标记时显示某个标记,并在标记未选中或未聚焦时显示另一个标记.根据我的理解,这是我写的:

public class MyItemizedOverlay extends ItemizedOverlay<MyOverlayItem> {

ArrayList<MyOverlayItem> items;
//...

public MyItemizedOverlay(Drawable drawable, /*...*/) {
    super(boundCenterBottom(drawable));
    //...
    populate();
}

public void addOverlay(MyOverlayItem overlay) {
    return this.items.add(overlay);
    populate();

@Override 
protected MyOverlayItem createItem(int index) {
    return this.items.get(index);
}

@Override
public int size() {
    return this.items.size();
}}

    public class MyOverlayItem extends OverlayItem {

//...

public Drawable getMarker(int stateBitset) {
    Drawable drawable;
    try {
        if (stateBitset == 0) {
            if (this.property.Equals("ON")) {
                drawable = this.context.getResources().getDrawable(R.drawable.on);
                drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
                return drawable;
            } else …
Run Code Online (Sandbox Code Playgroud)

android google-maps overlayitem itemizedoverlay

2
推荐指数
1
解决办法
7351
查看次数