2013-07-04 65 views
0

因此,當我更改我的地圖視圖時,我設置了一些調試以記錄visibleMapRect。當我以我想要的方式得到視圖時,我記下了這些值,並在viewDidLoad中將mapView設置爲該矩形。然而它不一樣的看法。它縮小得更多,所以我看到的是以屏幕爲中心,但屏幕上還有更多。MapKit,設置視圖

如何將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

iOS系統版本? – AlexWien

+0

多個版本(6&7) – Justin808

+0

也許'setVisibleMapRect:edgePadding:animated:'是一個解決方案嗎? – Mundi

回答

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];