これは OnTouch の私のコードです。ポップアップを表示する別の onTap メソッドがあります。ただし、OnTouch が OnTap でオーバーラップしているため、発生していません。したがって、この OnTouchEvent 関数を OnTap に変換するにはどうすればよいですか。この onTouch 関数を削除すると、マーカーをドラッグできなくなるためです。
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
final int action=event.getAction();
final int x=(int)event.getX();
final int y=(int)event.getY();
boolean result=false;
p = map.getProjection().fromPixels(x, y);
newP = p;
if (action==MotionEvent.ACTION_DOWN) {
for (OverlayItem item : items) {
Point pa=new Point(0,0);
map.getProjection().toPixels(item.getPoint(), pa);
//I maintain the hitTest's bounds so you can still
//press near the marker
if (hitTest(item, marker, x-pa.x, y-pa.y)) {
result=true;
inDrag=item;
items.remove(inDrag);
populate();
//Instead of using the DragImageOffSet and DragTouchOffSet
//I use the x and y coordenates from the Point
setDragImagePosition1(x, y);
dragImage.setVisibility(View.VISIBLE);
break;
}
}
}
else if (action==MotionEvent.ACTION_MOVE && inDrag!=null) {
setDragImagePosition1(x, y);
result=true;
}
else if (action==MotionEvent.ACTION_UP && inDrag!=null) {
dragImage.setVisibility(View.GONE);
//I get the geopoint without using any OffSet, directly with the
//Point coordenates
p=map.getProjection().fromPixels(x,y);
OverlayItem toDrop=new OverlayItem(p, inDrag.getTitle(),
inDrag.getSnippet());
Drawable orig = inDrag.getMarker(0);
//In my case I had down heading Arrows as markers, so I wanted my
//bounds to be at the center bottom
if( orig != null)
toDrop.setMarker(boundCenterBottom(orig));
items.add(toDrop);
populate();
inDrag=null;
result=true;
}
return(result || super.onTouchEvent(event, mapView));
}
private void setDragImagePosition1(int x, int y) {
RelativeLayout.LayoutParams lp=
(RelativeLayout.LayoutParams)dragImage.getLayoutParams();
//Instead of using OffSet I use the Point coordenates.
//I want my arrow to appear pointing to the point I am moving, so
//I set the margins as the Point coordenates minus the Height and half the
//width of my arrow.
lp.setMargins(x-(dragImage.getWidth()/2),y-dragImage.getHeight(), 0, 0);
dragImage.setLayoutParams(lp);
}