当我编译并运行我的应用程序时,地图视图不会像我一样缩放到位置
.h文件包含以下内容

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface myContactUsViewController : UIViewController

@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@end

.m文件包含以下内容
#import "myContactUsViewController.h"
#define METERS_PER_MILE 1609.344
@interface myContactUsViewController ()

@end

@implementation myContactUsViewController



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated {
    // 1
    CLLocationCoordinate2D zoomLocation;
    zoomLocation.latitude = 39.281516;
    zoomLocation.longitude= -76.580806;

    // 2
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);

    // 3
    [_mapView setRegion:viewRegion animated:YES];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.




}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end

最佳答案

CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = 39.281516;
zoomLocation.longitude= -76.580806;
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.18;
span.longitudeDelta=0.18;
region.span=span;
region.center= zoomLocation;
[self.mapView setRegion:region animated:TRUE];
[self.mapView regionThatFits:region];

关于ios - MKMapView map View 未缩放到位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18885222/

10-11 14:20