2012-07-19 113 views
0

我查看了現有的問題,並相信我遵循規則,但某些原因導致我的地圖不縮放。我已經放置了一個斷點,以確保我的座標正在通過,並且在那裏一切似乎都沒有問題。mapView不縮放到座標

以下是我的代碼。

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self configureView]; 

    mapView = [[MKMapView alloc]initWithFrame:CGRectMake(20, 20, 260, 169)]; 
    mapView.delegate = self; 
    mapView.mapType = MKMapTypeStandard; 
    [self.view addSubview:mapView]; 
} 

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated { 

    Bar *maps = self.detailItem; 
    MKCoordinateSpan span; 
    span.latitudeDelta = .02; 
    span.longitudeDelta = .02; 

    CLLocationDegrees latDegree = [maps.barLat doubleValue]; 
    CLLocationDegrees longDegree = [maps.barLong doubleValue]; 
    CLLocationCoordinate2D location = CLLocationCoordinate2DMake(latDegree, longDegree); 

    MKCoordinateRegion region; 
    region.center = location; 
    region.span = span; 
    [mapView setRegion:region animated:TRUE]; 
} 

回答

0

我並不完全清楚你想在mapView:regionWillChangeAnimated:回調......當區域將改變(上如用戶平移或縮放)被調用做什麼,你都響應通過指揮另一個地區的變化。也許這只是爲了調試?

我認爲你的問題是關於你的地圖爲什麼不放大,對吧?

如果你想確保你的地圖支持變焦,添加以下代碼:

mapView = [[MKMapView alloc]initWithFrame:CGRectMake(20, 20, 260, 169)]; 
mapView.delegate = self; 
mapView.mapType = MKMapTypeStandard; 
mapView.zoomEnabled = YES; 
mapView.multipleTouchEnabled = YES; 

不過,我想知道,如果你看到的只是你的地圖是非常小的。它不到屏幕尺寸的一半。在模擬器上,我發現很難執行捏合手勢(這會導致變焦),甚至在我的真實設備上,將兩根手指伸入該小視圖區也不容易。但是,在這兩個平臺上,我確實看到允許縮放的代碼(iOS 5.0)。

您可以增加地圖尺寸frame,並確保它不僅僅是在一個小區域內捏住很難嗎?