jeudi 13 août 2015

Android MapView Multiple Random Markers Removal with Double Tap On Marker

I have question about marker. Looks like after I created next marker, the onDoubleTap method of the marker is no longer available for PREVIOUS markers (NOT the last marker created). Any suggestion on how to fix it where I want to be able to remove it each markers randomly with double tapping on it via onDoubleTap method? What is causing for PREVIOUS markers to no lose track of onDoubleTap method? I have notice is I can double tap anywhere in the map and LAST marker disappears. I want only when doubled tapped ON TOP of that marker it only disappears. Also, when my map rotates markers disappears.

Overlay touchOverlay = new Overlay(this) {
ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay = null;

@Override
protected void draw(Canvas arg0, MapView arg1, boolean arg2) {

}

 @Override
 public boolean onSingleTapConfirmed(final MotionEvent e,
 final MapView mapView) {
 Projection proj = mapView.getProjection();
 GeoPoint loc = (GeoPoint) proj.fromPixels((int) e.getX(),
 (int) e.getY());
 ArrayList<OverlayItem> overlayArray = new ArrayList<OverlayItem>();
 OverlayItem mapItem = new OverlayItem("", "", new GeoPoint(
 (((double) loc.getLatitudeE6()) / 1000000),
 (((double) loc.getLongitudeE6()) / 1000000)));
 mapItem.setMarker(OfflineMapDemoActivity.this.getResources()
 .getDrawable(R.drawable.location_mark));
 overlayArray.add(mapItem);
 anotherItemizedIconOverlay = new ItemizedIconOverlay<OverlayItem>(
                        getApplicationContext(), overlayArray, null);
 mapView.getOverlays().add(anotherItemizedIconOverlay);
 mapView.invalidate();
 return true;
 }


@Override
public boolean onDoubleTap(MotionEvent e, MapView mapView) {
//remove marker here
mapView.getOverlays().remove(anotherItemizedIconOverlay);
mapView.invalidate();
return true;
}
}; //end of Overlay

mapView.getOverlays().add(touchOverlay);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire