我的地图应该缩放到保存在 NSUserDefaults 中的位置。虽然我的图钉显示在地图上,但地图会进入大海,根本不会缩放。这是我的代码。我究竟做错了什么?
我确实定义了#define METERS_PER_MILE 1609.344
-(void)viewWillAppear:(BOOL)animated{
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
if ([ud boolForKey:@"headquarters_coordinates"])
{
CLLocationCoordinate2D savedCoordinate;
savedCoordinate.latitude = [ud doubleForKey:@"headquarters_latitude"];
savedCoordinate.longitude = [ud doubleForKey:@"headquarters_longitude"];
//create annotation object using savedCoordinate and add to map view...
NSLog(@"Your HQ is at coordinates %f and %f",savedCoordinate.latitude, savedCoordinate.longitude);
MapViewAnnotation *ann1 =[[MapViewAnnotation alloc] init];
ann1.title=@"HQ";
ann1.subtitle=@"";
ann1.coordinate= savedCoordinate;
[mapView addAnnotation:ann1];
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(savedCoordinate, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);
[mapView setRegion:viewRegion animated:YES];
}
}