我想为应用程序设置一个默认区域,每次打开地图时它都应该显示一个区域。例如,每次我打开地图时,它都应该显示“伦敦”。
我这样做了,但它没有居中
@interface AppleMapViewController ()
@end
@implementation TicinoWineAppleMapViewController
@synthesize mapView = _mapView;
#define DEFAULT_LATITUDE 46.006512
#define DEFAULT_LONGITUDE 8.952312
#define THE_SPAN 10.0f
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewWillAppear:(BOOL)animated
{
NSLog(@"ViewWillAppear");
}
- (void)createDefaultRegion
{
MKCoordinateRegion defaultRegion;
CLLocationCoordinate2D center;
center.latitude = DEFAULT_LATITUDE;
center.longitude = DEFAULT_LONGITUDE;
MKCoordinateSpan span;
span.latitudeDelta = THE_SPAN;
span.longitudeDelta = THE_SPAN;
// defaultRegion.center = center;
// defaultRegion.span = span;
defaultRegion = MKCoordinateRegionMake(center, span);
TicinoWineMapViewAnnotation *annotation = [[TicinoWineMapViewAnnotation alloc]initWithTitle:@"ciao" andCoordinate:center];
[_mapView addAnnotation:annotation];
[_mapView setRegion:defaultRegion animated:YES];
[_mapView setCenterCoordinate:center animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self createDefaultRegion];
}
@end
我尝试了两种方法:
[_mapView setRegion:defaultRegion animated:YES];
[_mapView setCenterCoordinate:center animated:YES];
但它并不以我想要的为中心。这可能是模拟器的问题?