0
我試圖用一組給定的座標打開地圖。它不工作。它僅在我退出視圖並再次輸入時纔有效。Apple Mapkit:地圖不以我給定的座標開頭
這裏是我的代碼 -
mapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface mapViewController : UIViewController <MKMapViewDelegate>
@property (strong, nonatomic) IBOutlet MKMapView *mapView;
@end
mapViewController.m
#import "mapViewController.h"
@interface mapViewController()
@end
@implementation mapViewController
@synthesize mapView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate = self;
CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = 39.281516;
zoomLocation.longitude= -76.580806;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(zoomLocation, 800, 800);
[self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];
}
@end
如果在'viewDidLoad'的最後一行設置'animated:NO',會發生什麼?如果這不起作用,您可以嘗試移動代碼以將地圖縮放到「viewWillAppear」或「viewDidAppear」。 –
:)我將代碼添加到viewDidAppear和BANG!它的工作,謝謝! –
@JakeSpencer你可能想添加這個答案。它爲什麼與viewDidAppear一起工作? –