如何设置地图的默认位置?例如,如果我想在爱尔兰设置它,我该怎么做?它目前默认为北美地区,但我希望它默认为某个坐标。
答案 0 :(得分:2)
以下代码将位置设置为SFO。根据您的需要更改坐标以设置所需的位置。
MKCoordinateRegion region = [mapView regionThatFits:MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake(37.78275123, -122.40345442), 200, 200)];
[mapView setRegion:region animated:YES];
如果您要查找用户的当前位置,请使用以下代码。
MKCoordinateRegion region = [mapView regionThatFits:MKCoordinateRegionMakeWithDistance(mapView.userLocation.coordinate, 200, 200)];
[mapView setRegion:region animated:YES];
答案 1 :(得分:0)
使用setRegion:animated
设置MKMapView
的初始区域:
-(void)viewDidLoad {
[super viewDidLoad];
self.mapView.delegate = self;
double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = 45.442424;
region.center.longitude = -122.78;
region.span.latitudeDelta = 0.60;
region.span.longitudeDelta = 0.60;
[mapView setRegion:region animated:YES];
});
}