Android onTap mapView method not working after removing all points

孤人 提交于 2020-01-06 15:40:11

问题


The onTap() method working when there is minimum one point on map but when I remove all points from map then onTap() method is not working and I am unable to add points on map.

Please help...

Code:

    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);
    }



}

The onTap method add point if the number of points in geoPointList is less than two.


回答1:


Finally solved, as I have implemented the custom MapOverlay and use the onTap method in it instead of using in CustomItemizedOverlay2.



来源:https://stackoverflow.com/questions/11902286/android-ontap-mapview-method-not-working-after-removing-all-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!