OverlayItem中的可点击列表(适用于Android的MapView)

时间:2011-11-16 01:07:09

标签: android listview android-mapview overlayitem

我有一个地图视图,其中有几个引脚绘制在不同的地址上。一切都很好。 如果有多个项目指向同一地址,则会出现此问题。 例如,

XYZ的ABC街1/45号 位于XYZ的ABC街7/45号单位。

我使用以下代码行来获取lat和long以创建GeoPoint。

List<Address> listfromGoogle = gc.getFromLocationName(a, 1);

其中a是地址,gc是GeoCoder对象。

根据API,上面提到的两个地址返回相同的坐标。

因此,在绘制地图上的引脚时,它们会相互覆盖,最后会有一个引脚用于多个地址。

我尝试实现一个显示气球上所有重复地址的列表。 这次尝试是徒劳的,我意识到了

OverlayItem(GeoPoint point, java.lang.String title, java.lang.String snippet) 

允许我只提供两个要在气球上显示的字符串。

关于如何挤入显示多个地址的List的任何线索?

1 个答案:

答案 0 :(得分:0)

您应该实现自定义OverlayItem

public class ListOverlayItem extends OverlayItem {
    private List<Address> list;

    public ListOverlayItem(GeoPoint point, List<Address> list) {
        super(point, "", "");
    }

    public List<Address> getList() {
        return list;
    }
}

然后在您的自定义ItemizedOverlay中,您可以使用此列表创建一个自定义对话框,其中包含onTap方法中的列表

public class ListItemizedOverlay extends ItemizedOverlay<ListOverlayItem> {

    @Override
    protected boolean onTap(int index) {
        // get item they tapped from index
        // use getList() to populate the listview in the custom dialog
    }
}