试图了解 MKMapView 的方法,但我已经学习了几个教程,但我似乎无法让它放大到我定义的位置,而是加载到以大西洋为中心的整个地图视图。我猜 iOS6 发生了一些变化,这意味着我正在使用的教程不再有效?(教程是iOS3-iOS5)。
我在 Interface Builder 中制作了一个 ViewController,给它一个 MapViewController 的自定义类。然后我拖动 MKMapView 并使用助手编辑器将其放入 MapViewController.h
MapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MapViewController : UIViewController
@property (weak, nonatomic) IBOutlet MKMapView *myMapView;
@end
MapViewController.m
#import "MapViewController.h"
#define CLS_LATITUDE 54.85477
#define CLS_LONGITUDE -1.57371
#define SPAN 0.10f;
@interface MapViewController ()
@end
@implementation MapViewController
@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 center;
center.latitude = CLS_LATITUDE;
center.longitude = CLS_LONGITUDE;
MKCoordinateSpan mySpan;
mySpan.latitudeDelta = SPAN;
mySpan.longitudeDelta = SPAN;
myRegion.center = center;
myRegion.span = mySpan;
[myMapView setRegion:myRegion animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end