2011-04-19 176 views
0

這裏iPhone MapView的區域放大是我的代碼:工作不正常

CLLocationCoordinate2D location; 
location.latitude = 50; 
location.longitude = -50; 
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, 5, 5); 

region.center=location; 
[mapView setShowsUserLocation:TRUE]; 
[mapView setDelegate:self]; 

[mapView setRegion:region animated:TRUE]; 
[mapView regionThatFits:region]; 
[self setView:mapView]; 

它會被放大,但太遠放大。 所以,如果我把它改成這樣:

CLLocationCoordinate2D location; 
location.latitude = 50; 
location.longitude = -50; 
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, 200, 200); 

region.center=location; 
[mapView setShowsUserLocation:TRUE]; 
[mapView setDelegate:self]; 

[mapView setRegion:region animated:TRUE]; 
[mapView regionThatFits:region]; 
[self setView:mapView]; 

將縮小所有的方式。有什麼我失蹤?

+0

你知道lat/long 50,-50是在大西洋嗎?而且距離是米? – Anna 2011-04-19 01:50:07

回答

0

對於第二個和第三個參數MKCoordinateRegionMakeWithDistance,5和200之間的數字是否會使該區域放大到中間量? docs表示這些參數是包含在該區域中的每個方向的距離。

1

這是因爲它在執行過早時調用了該方法。我添加了一個viewWillLoad,它在加載後會被調用,然後一切正常。謝謝您的幫助。