I made a category to save the map rect to the user defaults:
NSUserDefaults+MKMapRect.h
@interface NSUserDefaults (MKMapRect)
//stores a map rect in user defaults
-(void)setMapRect:(MKMapRect)mapRect forKey:(NSString*)key;
//retrieves the stored map rect or returns the world rect if one wasn't previously set.
-(MKMapRect)mapRectForKey:(NSString*)key;
@end
NSUserDefaults+MKMapRect.m
@implementation NSUserDefaults (MKMapRect)
-(void)setMapRect:(MKMapRect)mapRect forKey:(NSString*)key{
NSMutableDictionary *d = [NSMutableDictionary dictionary];
[d setObject:[NSNumber numberWithDouble:mapRect.origin.x] forKey:@"x"];
[d setObject:[NSNumber numberWithDouble:mapRect.origin.y] forKey:@"y"];
[d setObject:[NSNumber numberWithDouble:mapRect.size.width] forKey:@"width"];
[d setObject:[NSNumber numberWithDouble:mapRect.size.height] forKey:@"height"];
[self setObject:d forKey:key];
}
-(MKMapRect)mapRectForKey:(NSString*)key{
NSDictionary *d = [self dictionaryForKey:key];
if(!d){
return MKMapRectWorld;
}
return MKMapRectMake([[d objectForKey:@"x"] doubleValue],
[[d objectForKey:@"y"] doubleValue],
[[d objectForKey:@"width"] doubleValue],
[[d objectForKey:@"height"] doubleValue]);
}
@end