Hello.
I have an application with two storyboards (one for iPad and one for iPhone). I use the following to set the map area:
-(void) viewWillAppear:(BOOL)animated
{
...
[self.mapView removeAnnotations:self.mapView.annotations];
self.mapLocations = [[NSMutableArray alloc]init];
self.showMapRect = MKMapRectNull;
[self addAnnotation];
[self.mapView setVisibleMapRect:self.showMapRect edgePadding:UIEdgeInsetsMake(30, 30, 30, 30) animated:YES];
}
-(void) addAnnotation
{
CLLocationCoordinate2D mapLocation;
IGAMapAnnotation *mapAnnotation;
// If a set of coordinates is empty, it will have an empty object @"".
// This object must be removed from the array, otherwise it will be an error.
// In order not to change the original array, we create a copy
NSMutableArray *coordinatesTempArray = [[NSMutableArray alloc]initWithArray:self.coordinatesArray copyItems:YES];
[coordinatesTempArray removeObject:@""];
// Calculate how many points are included in the final flightplan
NSInteger numberOfPoints = [coordinatesTempArray count];
// Annotations will be added only of the flight plan includes at least one point
if (numberOfPoints > 0) {
// Place all annotations so that are are visible on the map using MKMapRect
for (NSInteger i=0; i < ([coordinatesTempArray count]); i++)
{
mapAnnotation = [[IGAMapAnnotation alloc]init];
// Taking a point in the array and getting its coordinates
self.mapCoordinates = [coordinatesTempArray objectAtIndex:i];
// Getting a point in the array and getting its latitude and longitude
self.mapLatitude = [[self.mapCoordinates objectAtIndex:0]doubleValue];
self.mapLongitude = [[self.mapCoordinates objectAtIndex:1]doubleValue];
// Assigning the point coordinates to the coordinates to be displayed on the map
mapLocation.latitude = self.mapLatitude;
mapLocation.longitude = self.mapLongitude;
// Adding coordinates to the map annotation
mapAnnotation.coordinate = mapLocation;
// Adding the annotation to the array that will be added to the map
[self.mapLocations addObject:mapAnnotation];
// Adding Annotation coordinates to MKMapRect so that they all be visible in the view
MKMapPoint annotationMapPoint = MKMapPointForCoordinate(mapLocation);
MKMapRect annotationMapRect = MKMapRectMake(annotationMapPoint.x, annotationMapPoint.y, 0, 0);
self.showMapRect = MKMapRectUnion(self.showMapRect, annotationMapRect);
}
}
// Adding annotations to the map
[self.mapView addAnnotations:self.mapLocations];
}It looks good on iPad (I wish I could upload images -- do not see this option). When the map opens, it has exactly the required span, all points on the map are visible. However, when I open the map on iPhone, the map is zoomed in, I see the central part, and the points are outside of the map boundaries.
My iPad application is landscape only, and iPhone -- portrait only.
Is there a way to have a map rect that would fit both?
Thanks a lot!
Two of those are redundant; I would remove the first and third if the intent is to resize it to fit the margins. In fact the third and last ones will conflict if the bottom margin changes to something nonzero - you would see errors in your console log.
Anyway. That doesn't answer the question 🙂 What is the frame at runtime? Is it the size you would expect?