2011-08-18 227 views
5

我試圖使用MKMapView。我成功地讓世界地圖出現。不過,我似乎無法改變區域:MKMapView設置區域

我有一個按鈕,將執行此:

NSLog(@"%f, %f, %f, %f, 
mapView.region.center.latitude, 
mapView.region.center.longitude, 
mapView.region.span.latitudeDelta, 
mapView.region.span.longitudeDelta); 

現在,在我的viewDidLoad的方法,我試圖起始區域設置爲視圖:

CLLocationCoordinate2D startCoord; 
startCoord.latitude = 49.0; 
startCoord.longitude = -123.0; 
[mapView setRegion:MKCoordinateRegionMakeWithDistance(startCoord, 200, 200) animated:YES]; 

當視圖確實加載時,它顯示了與預期相同的世界地圖而不是較小的區域。立即登錄該區域的屬性,給我:

0.000000,0.001417,0.000000,0.000000

移動地圖張望了一下,調整大小和縮放不會改變這些值(除了第二個追溯到0.000000) 。

這似乎是mapView.region不對應我在屏幕上看到的,但我很確定我正確地製作了IB鏈接,現在我正在查看它們。可能是什麼問題呢?

+0

[MapView的regionThatFits:MKCoordinateRegionMakeWithDistance(startCoord,200,200);將此行添加到您的代碼中。 – Harsh

回答

24

你需要做的

CLLocationCoordinate2D startCoord = CLLocationCoordinate2DMake(49, -123); 
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:MKCoordinateRegionMakeWithDistance(startCoord, 200, 200)]; 
[mapView setRegion:adjustedRegion animated:YES];