I have search for google map center while zooming using double tap and pinch to zoom. I have found one solution for Here, This is only for double Tap to zoom solution.
Well, I've found that when trying to do this, a successful pinch-to-zoom involves both velocity and scale condition. Velocity is measured to determine whether you really want to zoom depending on how fast you moved the two fingers away from or closer to each other, you can try this inside Google Maps and inside Uber's app, you can actually keep moving the fingers away from or closer to each other but so slowly that you will not trigger a zoom in/out event on the map!
So definitely involves velocity when trying to determine a full pinch gesture. Second of course you need scale also, and I've printed out the scale value and it is always smaller than exactly 1.0 when you start pinching to zoom out and always larger than 1.0 when you start pinching to zoom in.
Combination of these two will definitely get you better results, see velocity first I'd say
private final ScaleGestureDetector.OnScaleGestureListener mScaleGestureListener
= new ScaleGestureDetector.SimpleOnScaleGestureListener() {
/**
* This is the active focal point in terms of the viewport. Could be a local
* variable but kept here to minimize per-frame allocations.
*/
float startingSpan;
float startFocusX;
float startFocusY;
@Override
public boolean onScaleBegin(ScaleGestureDetector scaleGestureDetector) {
startingSpan = scaleGestureDetector.getCurrentSpan();
startFocusX = scaleGestureDetector.getFocusX();
startFocusY = scaleGestureDetector.getFocusY();
return true;
}
@Override
public boolean onScale(ScaleGestureDetector scaleGestureDetector) {
float scale = scaleGestureDetector.getCurrentSpan() / startingSpan;
mVelocityTracker.computeCurrentVelocity(1000);
Log.d("VELOCITY", "X vel : " + mVelocityTracker.getXVelocity());
Log.d("VELOCITY", "Y vel : " + mVelocityTracker.getYVelocity());
if (scale <= 1.0) {
EventBus_Singleton.getInstance().post(new EventBus_Poster("pinched_map", "out"));
} else {
EventBus_Singleton.getInstance().post(new EventBus_Poster("pinched_map", "in"));
}
return true;
}
};