2017-04-03 18 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); 

} 
を追加します。
関連する問題