Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there way to limit MKMapView maximum zoom level?

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?

like image 287
Vladimir Avatar asked Oct 28 '09 12:10

Vladimir


People also ask

How do you get zoom level in MKMapView?

The easiest way to get an Integer of the current zoom level, is by using the MapView function: regionDidChangeAnimated. This function recognizes every change in zoom and will give you the basis for the calculation of the zoom factor.

What is the maximum zoom level in Google map?

Overview. The Google Maps API provides map tiles at various zoom levels for map type imagery. Most roadmap imagery is available from zoom levels 0 to 18, for example. Satellite imagery varies more widely as this imagery is not generated, but directly photographed.

What is MKMapView?

The MKMapView class supports the ability to annotate the map with custom information. Because a map may have large numbers of annotations, map views differentiate between the annotation objects used to manage the annotation data and the view objects for presenting that data on the map.


2 Answers

If you're working with iOS 7+ only, there's a new camera.altitude property that you can get/set to enforce a zoom level. Its equivalent to azdev's solution, but no external code is required.

In testing, I also discovered that it was possible to enter an infinite loop if you repeatedly tried to zoom in at detail, so I have a var to prevent that in my code below.

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {     // enforce maximum zoom level     if (_mapView.camera.altitude < 120.00 && !_modifyingMap) {         _modifyingMap = YES; // prevents strange infinite loop case          _mapView.camera.altitude = 120.00;          _modifyingMap = NO;     } } 
like image 117
Ted Avery Avatar answered Sep 22 '22 20:09

Ted Avery


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 
like image 39
nevan king Avatar answered Sep 23 '22 20:09

nevan king