I have an app, that uses MapKit.
I calculate current zoom after resizing a map.
By define (from MKGeometry.h
file)
MKZoomScale provides a conversion factor between MKMapPoints and screen points.
When MKZoomScale = 1, 1 screen point = 1 MKMapPoint. When MKZoomScale is
0.5, 1 screen point = 2 MKMapPoints.
So, I calculate it in this way:
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
CGSize screenSize = mapView.bounds.size;
MKMapRect mapRect = mapView.visibleMapRect;
MKZoomScale zoomScale = screenSize.width * screenSize.height / (mapRect.size.width * mapRect.size.height);
}
The calculated zoomScale
conforms to definition (I've checked).
I also draw an overlay on my mapView in method
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
The problem is, that my calculated zoomScale
is not equal to that one, that passed to this method by system. I expect them to be equal, because drawMapRect:
calls just after resizing (actually, resizing causes this method to be called).
What is wrong here?
I also tried to use
currentZoomScale = mapView.bounds.size.width / mapView.visibleMapRect.size.width;
, suggested here, but this currentZoomScale
is not equal to passed to drawMapRect:
as well.