We\'re building an application which is using the google maps api for android.
I have my MapController and MapView, and I enable the built-in zoom controls using:
Here is a clean solution. Simply add this TouchOverlay private class to your activity and a method called onZoom (that is called by this inner class).
Note, you'll have to add this TouchOverlay to your mapView e.g.
mapView.getOverlays().add(new TouchOverlay());
It keeps track of the zoom level whenever the user touches the map e.g. to double-tap or pinch zoom and then fires the onZoom method (with the zoom level) if the zoom level changes.
private class TouchOverlay extends com.google.android.maps.Overlay {
int lastZoomLevel = -1;
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapview) {
if (event.getAction() == 1) {
if (lastZoomLevel == -1)
lastZoomLevel = mapView.getZoomLevel();
if (mapView.getZoomLevel() != lastZoomLevel) {
onZoom(mapView.getZoomLevel());
lastZoomLevel = mapView.getZoomLevel();
}
}
return false;
}
}
public void onZoom(int level) {
reloadMapData(); //act on zoom level change event here
}