那是我的代码:
OverlayItem overlayItem = new OverlayItem(point, "Test", "Hello");
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
当我运行这个应用程序时,我可以看到地图上有我的项目,但点击它时没有任何反应。我期待一种带有“Test [...] Hello”的消息框。我猜我忘记了什么。谢谢你的帮助。
答案 0 :(得分:1)
覆盖onTap(int index),如下所示...........
public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
private Context context;
public CustomItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public CustomItemizedOverlay(Drawable defaultMarker, Context context) {
this(defaultMarker);
this.context = context;
}
@Override
protected OverlayItem createItem(int i) {
return mapOverlays.get(i);
}
@Override
public int size() {
return mapOverlays.size();
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mapOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
public void addOverlay(OverlayItem overlay) {
mapOverlays.add(overlay);
this.populate();
}
}