删除所有点后,Android onTap mapView方法无法正常工作

时间:2012-08-10 13:06:19

标签: android itemizedoverlay

onTap()方法在地图上至少有一个点时工作,但是当我从地图中删除所有点时,onTap()方法无效,我无法在地图上添加点。

请帮忙......

代码:

    private class CustomItemizedOverlay2 extends ItemizedOverlay<OverlayItem> {

    private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
    private Context context;
    private GeoPoint center = null;

    public CustomItemizedOverlay2(Drawable defaultMarker) {
        super(boundCenterBottom(defaultMarker));
    }

    public CustomItemizedOverlay2(Drawable defaultMarker, GeoPoint point) {
        this(defaultMarker);
        OverlayItem overlayItem = new OverlayItem(point, "", "");
        mapOverlays.add(overlayItem);
        populate();
    }

    public CustomItemizedOverlay2(Drawable defaultMarker, Context context,
            String result) {
        this(defaultMarker);
        this.context = context;

        for (int i = 0; i < geoPointList.size(); i++) {
            OverlayItem overlayItem = new OverlayItem(geoPointList.get(i),
                    "abc", "point" + i);
            mapOverlays.add(overlayItem);
        }
        populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
        return mapOverlays.get(i);
    }

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

    @Override
    public boolean onTap(GeoPoint point, MapView mapView) {

        int size = geoPointList.size();
        if (size < 2) {
            geoPointList.add(point);

            count++;
            int lat = point.getLatitudeE6();
            int longi = point.getLongitudeE6();
            Drawable image = gMap.this.getResources().getDrawable(
                    R.drawable.pushpin);

            CustomItemizedOverlay2 addPointItemizedOverlay = new CustomItemizedOverlay2(
                    image, point);
            mapView.getOverlays().add(addPointItemizedOverlay);


            mapView.invalidate();
        }
        return super.onTap(point, mapView);
    }



}

如果geoPointList中的点数小于2,则onTap方法添加点。

1 个答案:

答案 0 :(得分:1)

最后解决了,因为我实现了自定义MapOverlay并在其中使用onTap方法而不是在CustomItemizedOverlay2中使用。