Alex Rivera | Logout

Is there way to limit MKMapView maximum zoom level?

Asked 2009-10-28T12:12:03.877
35

the question is - is there a way to limit maximum zoom level for MKMapView? Or is there a way to track when user zooms to the level where there's no map image available?

Edit
Report

2 Answers

29

You could use the mapView:regionWillChangeAnimated: delegate method to listen for region change events, and if the region is wider than your maximum region, set it back to the max region with setRegion:animated: to indicate to your user that they can't zoom out that far. Here's the methods:

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
- (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated
answered 2009-10-28T13:59:14.303
15

Yes, this is doable. First, extend MKMapView by using MKMapView+ZoomLevel.

Then, implement this in your MKMapViewDelegate:

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    // Constrain zoom level to 8.
    if( [mapView zoomLevel] < 8 )
    {
        [mapView setCenterCoordinate:mapView.centerCoordinate 
            zoomLevel:8 
            animated:NO];
    }
}
answered 2011-10-06T19:35:08.587

Your Answer