如何让MKMapView从顶部进入

时间:2016-05-01 12:16:09

标签: ios objective-c mapkit core-location

我有一个普通的MKMap视图,带有基本的MKAnnoation,我想要完成的是我的注释在英国,MKCoordinateSpan是0.05但我希望MKMapView从整个英国的视图开始并放大到注释

1 个答案:

答案 0 :(得分:0)

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    /* set here the region from where map will be zooming; */
    [self.mapView setRegion:MKCoordinateRegionForMapRect(MKMapRectWorld) animated:NO];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    /* set here your end point of zooming */
    CLLocationCoordinate2D zoomLocation;
    zoomLocation.latitude = 39.281516;
    zoomLocation.longitude= -76.580806;

    [self.mapView setCenterCoordinate:zoomLocation animated:YES];
    CLLocationDistance locationDistance = [self locationDistance:0.5];
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, locationDistance, locationDistance);
    [self.mapView setRegion:viewRegion animated:YES];
}

- (CLLocationDistance )locationDistance:(CGFloat )value {
    return 1609.344 *value;
}