0

Initially I am able to add the pin on the map.I delete the pin using

mapView.getOverlays().clear();
mapView.invalidate();

Now when I click on addPin button the same code of adding the pin on map runs, but it does not get added on it. Please Help.....

Code for adding pin is:-

addPin.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            ch=1;



        }
    });

After clicking the add button i touch on the place where I want to add PIN

view.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent motionEvent) {

            Toast.makeText(getApplicationContext(), "done", Toast.LENGTH_SHORT).show();

            itemizedoverlay.populateList();
            if(ch==1){
            GeoPoint point = view.getProjection().fromPixels(
                    (int) motionEvent.getX(),
                    (int) motionEvent.getY());

            overlayitem = new OverlayItem(point, "Yeahh", "I've added");


            itemizedoverlay.addOverlay(overlayitem);

            mapOverlays.add(itemizedoverlay);

            Toast.makeText(getApplicationContext(), "Added", Toast.LENGTH_SHORT).show();

            ch=0;
            }
            Toast.makeText(getApplicationContext(), "done", Toast.LENGTH_SHORT).show();
            return false;
        }
    });

Here view=mapView I am using counter ch which will change to ch=0 when added and when deleted it will get turned to ch=1

code for deleting:-

delete.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub


        view.getOverlays().clear();
        view.invalidate();

        }
    });
aagam94
  • 613
  • 1
  • 6
  • 20

1 Answers1

0

Your call to mapView.getOverlays() returns List containing all overlays, so when you call clear() on it, you remove all overlays.

Try calling clear() on a single Overlay. If this method isn't there, add it. And, by the way, invalidate() shouldn't be used for repaint, use populate() on your Overlay instead.

Andrii Chernenko
  • 9,873
  • 7
  • 71
  • 89