[英]How to control pinch zoom in, zoom out on a map in Android?
In my Android app I've a MapActivity where, when zooming the map with two fingers (pinch) it's zooming, but when I lift the fingers it's zooming further. 在我的Android应用程序中,我有一个MapActivity,当用两个手指(捏)缩放地图时,它会缩放,但当我抬起手指时,它会进一步缩放。 Meaning, if London is centered on the map, when I am zooming London reaches the edges of the screen;
意思是,如果伦敦以地图为中心,当我缩放时伦敦到达屏幕的边缘; when I lift the fingers, it is going out of screen, zooming further.
当我抬起手指时,它会离开屏幕,进一步缩放。 I want it like iOS map app (No further zooming).
我希望它像iOS地图应用程序(没有进一步缩放)。 How can I do this?
我怎样才能做到这一点?
I tried the following code but did not work. 我尝试了以下代码,但没有奏效。
class MapOvelay extends Overlay {
boolean moveTouch;
int i;
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
switch (event.getAction()) {
case MotionEvent.ACTION_POINTER_UP://when two fingers are lifted
mapController.setZoom(i);
i=0;
break;
case MotionEvent.ACTION_MOVE://when two fingers are moving on map
i = mapView.getZoomLevel();
moveTouch = true;
break;
....
}
}
}
Have you tried the zoomToSpan-functionality? 你试过zoomToSpan功能吗?
mMapController.zoomToSpan(maxLatitude - minLatitude,maxLongitude - minLongitude);
Also, you can restrict lowest zoom with something like this 此外,您可以使用类似的内容限制最低缩放
if (LOWEST_ZOOM_LEVEL < mMap.getZoomLevel() ) {
mMapController.setZoom(LOWEST_ZOOM_LEVEL);
}
You can get the maximum zoom level available by calling #getMaxZoomLevel() in your MapView. 您可以通过在MapView中调用#getMaxZoomLevel()来获得可用的最大缩放级别。 That's the closest zoom you will be able to get, no matter what happens in the official Google Maps application.
无论官方Google地图应用程序发生什么,这都是您能够获得的最接近的缩放。
mapView.getController().animateTo(geoPoint);
mapView.getController().setZoom(15);
mapView.invalidate();
Try this 尝试这个
mapview.getController().animateTo(startGP);
mapview.getController().setZoom(13);
mapview.setBuiltInZoomControls(true);
mapview.invalidate();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.