gpt4 book ai didi

ios - MKMapView map View 未缩放到位置

转载 作者:行者123 更新时间:2023-11-28 22:26:13 24 4
gpt4 key购买 nike

当我编译并运行我的应用程序时, 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com