I have to fit the pins to the visible map so I get the MKMapRect with the well-known lines of code:
MKMapRect mapRect = MKMapRectNull;
for(id<MKAnnotation> annotation in [self.mapView annotations]){
if (![annotation isKindOfClass:[MKUserLocation class]]) {
MKMapPoint annotationPoint = MKMapPointForCoordinate([annotation coordinate]);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, delta, delta);
mapRect = MKMapRectUnion(mapRect, pointRect);
}
}
then I get and set the MKCoordinateRegion
with:
MKCoordinateRegion region = MKCoordinateRegionForMapRect(newMapRect);
MKCoordinateRegion fitRegion = [self.mapView regionThatFits:region];
[self.mapView setRegion:fitRegion animated:animated];
Since I use have two states (open and close map) close is where the map is not totally visible (the origin.y value on self.view
is negative) I need to redraw the rect when the method "fitToAnnotations" is called I use [self.mapView setNeedsLayout];
so I can get the correct self.mapView.frame
(open or close).
Now, If i use this code, with some others lines, in iOS7 everything works good but with iOS 7.1 the open-map-Region is different showing a big edge Region without pins and all fitted in the center portion.
Here is how i get the correct region to show if the map is full or half screen size
MKMapRect newMapRect = mapRect;
if (mapFullScreen) {
newMapRect = [self.mapView mapRectThatFits:mapRect edgePadding:UIEdgeInsetsMake(200, 15, 30, 15)];
}else{
MKMapView *smallMap = [[MKMapView alloc] initWithFrame:self.homeViewController.tableView.tableHeaderView.frame];
newMapRect = [smallMap mapRectThatFits:mapRect edgePadding:UIEdgeInsetsMake(15, 60, 5, 60)];
smallMap = nil;
}
what's going wrong?