2017-04-03 19 views

답변

0

다음 코드를 사용하여 문제가 해결되었습니다.

하는 코드 아래에 추가 OnMapReady 방법은 클래스

private ScaleGestureDetector gestureDetector; 
private long lastZoomTime = 0; 
private float lastSpan = -1; 
private long firstClick=0; 
private long lastClick; 
GoogleMap mMap; 

에서 변수를 만듭니다 :

mMap = googleMap; 
gestureDetector = new ScaleGestureDetector(getApplicationContext(), new ScaleGestureDetector.OnScaleGestureListener() { 
     @Override 
     public boolean onScale(ScaleGestureDetector detector) { 
      Log.i("onScale ", " onScale "); 
      if (lastSpan == -1) { 
       lastSpan = detector.getCurrentSpan(); 
      } 
      if (detector.getEventTime() - lastZoomTime >= 50) { 
       lastZoomTime = detector.getEventTime(); 
       mMap.animateCamera(CameraUpdateFactory.zoomBy(getZoomValue(detector.getCurrentSpan(), lastSpan)), 50, null); 
       lastSpan = detector.getCurrentSpan(); 
      } 
      return false; 
     } 

     @Override 
     public boolean onScaleBegin(ScaleGestureDetector detector) { 
      lastSpan = -1; 
      return true; 
     } 

     @Override 
     public void onScaleEnd(ScaleGestureDetector detector) { 
      lastSpan = -1; 

     } 


    }); 

수업 시간에 방법 아래의 추가

private float getZoomValue(float currentSpan, float lastSpan) { 
    Log.i("ongetZoomValue ", " getZoomValue "); 
    double value = (Math.log(currentSpan/lastSpan)/Math.log(1.55d)); 
    return (float) value; 
} 

public boolean dispatchTouchEvent(MotionEvent ev) { 

    //Log.i("on dispatchTouchEvent ", " dispatchTouchEvent "); 
    switch (ev.getAction() & MotionEvent.ACTION_MASK) { 




     case MotionEvent.ACTION_POINTER_DOWN: 
      fingers = fingers + 1; 

      break; 
     case MotionEvent.ACTION_POINTER_UP: 

      fingers = fingers - 1; 
      break; 
     case MotionEvent.ACTION_UP: 
      fingers = 0; 
      break; 
     case MotionEvent.ACTION_DOWN: 


      if (firstClick != 0 && System.currentTimeMillis() - firstClick > 300) { 
       Log.i("on count=0", " count=0 "); 
       count = 0; 
      } 
      count++; 
      if (count == 1) { 
       Log.i("on count ", " count=1 "); 
       firstClick = System.currentTimeMillis(); 
      } else if (count == 2) { 
       Log.i("on count ", " count=2 "); 
       lastClick = System.currentTimeMillis(); 
       if (lastClick - firstClick < 300) { 

        CameraUpdate getzoom = CameraUpdateFactory.zoomIn(); 
        mMap.animateCamera(getzoom, 400, null); 
        Log.i("on double click ", " event "); 
       } 

      } 


      fingers=1; 
      break; 
    } 

    if (fingers >1) { 

     //Log.i("2fingersaction ", "2fingersaction "); 
     mMap.getUiSettings().setScrollGesturesEnabled(false); 
     //mMap.getUiSettings().setRotateGesturesEnabled(false);   // disableScrolling() 
    } 
    else if (fingers < 1) 
    { 
     //Log.i("onefinger ", "onefinger "); 

     mMap.getUiSettings().setScrollGesturesEnabled(true); 
     // enableScrolling(); 
    } 
    if (fingers > 1) { 

     //Log.i("double if condition ", "doubleifcondition "); 


     return gestureDetector.onTouchEvent(ev); 

    } else 

     return super.dispatchTouchEvent(ev); 

}