我的情节提要上有一个 MKMapView,当我转到情节提要时,只是加载默认视图,而不是规格已设置的经纬度和跨度,但不会缩放到我正在寻找的位置。
这是.h
//
// ContactViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface ContactViewController : UIViewController
@property (weak, nonatomic) IBOutlet MKMapView *myMapView;
@end
这是.m
//
// ContactViewController.m
#import "ContactViewController.h"
@interface ContactViewController ()
@end
// define long and lat of location
#define map_long 42.877391;
#define map_lat -80.734766;
// define span
#define map_span 0.05f;
@implementation ContactViewController
@synthesize myMapView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
//[super viewDidLoad];
MKCoordinateRegion myregion;
CLLocationCoordinate2D mycenter;
mycenter.latitude = map_lat;
mycenter.longitude = map_long;
MKCoordinateSpan myspan;
myspan.latitudeDelta = map_span;
myspan.longitudeDelta = map_span;
myregion.center = mycenter;
myregion.span = myspan;
// Do any additional setup after loading the view.
[myMapView setRegion:myregion animated:YES];
[myMapView setCenterCoordinate:mycenter animated:YES];
}
@end