所以当我更改地图视图时,我设置了一些调试来记录visibleMapRect
。当我按照我想要的方式获取视图时,我记下了值,并在viewDidLoad
中将mapView设置为该rect。然而它的观点不一样。它被缩小了更多,所以我所看到的是以屏幕为中心,但屏幕上也有更多。
如何将mapView设置为与我设置的相同?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
MKMapRect mRectHawaii;
mRectHawaii.origin.x = 16077095.369230;
mRectHawaii.origin.y = 117612734.225784;
mRectHawaii.size.width = 698548.708173;
mRectHawaii.size.height = 393548.573271;
[self.mapView setVisibleMapRect:mRectHawaii animated:NO];
}
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
MKMapRect mRect = mapView.visibleMapRect;
NSLog(@"(%f, %f) (%f, %f)", mRect.origin.x, mRect.origin.y, mRect.size.width, mRect.size.height);
}
答案 0 :(得分:0)
MKMapRect zoomRect = MKMapRectNull;
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0.1, 0.1);
if (MKMapRectIsNull(zoomRect)) {
zoomRect = pointRect;
}else{
zoomRect = MKMapRectUnion(zoomRect, pointRect);
}
}
[[self mapview] setVisibleMapRect:zoomRect edgePadding:UIEdgeInsetsMake(50, 50, 50, 50) animated:YES];