如何在Android中控制捏放大,缩小地图



在我的Android应用程序中,我有一个MapActivity,当用两根手指(捏合)缩放地图时,它会缩放,但是当我抬起手指时,它会进一步缩放。意思是,如果伦敦在地图上居中,当我缩放伦敦时会到达屏幕的边缘;当我抬起手指时,它正在退出屏幕,进一步缩放。我希望它像iOS地图应用程序一样(没有进一步缩放)。我该怎么做?

我尝试了以下代码,但没有工作。

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;
   .... 
  }
 }
}

你试过zoomToSpan功能吗?

mMapController.zoomToSpan(maxLatitude - minLatitude,maxLongitude - minLongitude);

此外,您可以使用这样的东西限制最低缩放

if (LOWEST_ZOOM_LEVEL < mMap.getZoomLevel() ) {
    mMapController.setZoom(LOWEST_ZOOM_LEVEL);
}

试试这个

    mapview.getController().animateTo(startGP);
    mapview.getController().setZoom(13);        
    mapview.setBuiltInZoomControls(true);
    mapview.invalidate();
您可以通过在

MapView 中调用 #getMaxZoomLevel() 来获得可用的最大缩放级别。这是您能够获得的最接近的缩放,无论在官方Google地图应用程序中发生什么。 mapView.getController().animateTo(geoPoint); mapView.getController().setZoom(15); mapView.invalidate();

最新更新