ios - MKMapView map View 未缩放到位置

标签 ios objective-c

当我编译并运行我的应用程序时, map View 不会像我想象的那样缩放到位置

.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/

相关文章:

ios - 如何在 Nativescript iOS 应用程序中实现使用 Google 登录?

iphone - 从/到字符串保存和加载 UIImage

ios - 如何在 iOS 中计时操作 - 测量性能速度?

objective-c - Objective C 初始化器基础

ios - RLMArray 到 RLMLinkingObjects 迁移

ios - 包装器-UIVIew 中的 MPVolumeView

ios - 如何在 Objective C 中的日历上添加来自 Web 服务的事件

ios - UITableViewCell Checkmark - 如何保存和检索 indexPath?

iphone - 代码 : How to change all fonts at once in an app?

ios - 使用平移移动将部分 Table View Cell 滑开