I\'m using MapKit on iPhone. How can I know when the user changes the zoom level (zoom in\\out the map)?
I\'ve tried to use mapView:(MKMapView *)mapView regi
you can listen to the mapView:regionDidChangeAnimated:
method. However, this doesn't tell you if the zoom level changed, just if the map was animated.
You will also need to listen to the region
property of the map view. This contains the latitudeDelta and the longitudeDelta values which can be used to calculate if the zoom level has changed.
i.e. in the .h file
@class MyMapViewController {
...
MKCoordinateRegion mapRegion;
}
@end
and in your .m file
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated {
mapRegion = mapView.region;
}
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
newRegion = mapView.region;
if (mapRegion.span.latitudeDelta != newRegion.span.latitudeDelta ||
mapRegion.span.longitudeDelta != newRegion.span.longitudeDelta)
NSLog(@"The zoom has changed");
}
This should detect if the map zoom has changed.
however, you should wach out for the zoom changing because the earth is curved :( If the map is scrolled the latitudeDelta and longitudeDelta will change slightly just because of the shape of the Earth, not because the user has zoomed. You might have to detect a large change in the deltas and ignore slight changes.
Hope that helps.