2012-06-15 2 views
0

이것은 OnTouch 용 코드입니다. 팝업을 표시하는 또 다른 onTap 메서드가 있습니다. 그러나 OnTouch가 OnTap에서 겹치기 때문에 해고 당하지는 않습니다. 따라서이 OnTouchEvent 함수를 OnTap으로 변환하려면 어떻게해야합니까? 이 onTouch 기능을 제거하면 마커를 드래그 할 수 없으므로OnTouch 및 OnTap 겹침. 할일은?

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

hello.i가이 문제를 해결했습니다. http://kyogs.blogspot.in/2013/02/mapview-drag-and-drop-marker-on-google.html – kyogs

답변

1

onTouch을 X 번 발사 한 후 포인터가 이동 한 평균 거리를 계산합니다. 일부 Y 값보다 작 으면 onTap 이벤트를 시작하십시오. 그렇지 않으면 드래그를 시작하십시오.

+0

나는 동일한 문제가 있지만 여전히 성공하지 못합니다. . – kyogs