2012-11-13 95 views
0

我有一個MKMapView,我試圖設置地圖,這樣當你第一次加載應用程序時,它會轉到用戶設置的位置,如果用戶還沒有設置,一個默認的。問題在於,它似乎總是處於0緯度,0經度。MKMapView不縮放到區域

-(void) viewDidLoad { 

    [worldView setShowsUserLocation:YES]; 

    double longitude = [[NSUserDefaults standardUserDefaults] doubleForKey:WhereamiNewLongPrefKey]; 

    double latitude = [[NSUserDefaults standardUserDefaults] doubleForKey:WhereamiNewLatPrefKey]; 

    CLLocationCoordinate2D savedLoc = CLLocationCoordinate2DMake(latitude, longitude); 

    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(savedLoc, 250, 250); 

    NSLog(@"latitude :%f", region.center.latitude);  
    NSLog(@"longitude :%f", region.center.longitude); 

    [worldView setRegion:region animated:YES]; 
} 

我試過設置setShowUserLocationNO,但不起作用。我知道它正在讀取正確的區域,因爲NSLog正在輸出默認的緯度,但是地圖堅持要去中國的某個地方...

我也嘗試在mapView:didUpdateUserLocation:中設置區域,但結果仍然相同。

我在做什麼錯?

編輯:我加了NSLog來輸出經度。輸出是:

2012-11-14 09:50:30.699 Whereami[34256:13d03] latitude :20.516700 
2012-11-14 09:50:30.699 Whereami[34256:13d03] longitude :99.900000 
+1

更改的NSLog打印出經度和緯度,並告訴我們它打印。你的經度可能是錯的。這是積極的嗎?那意味着它在東半球。 – Craig

+0

您正在使用模擬器還是設備進行測試? – rockstarberlin

+0

@rockstarberlin我已經在模擬器和設備上進行了測試。 – coopersita

回答

0
CLLocationCoordinate2D theCoordinate; 
theCoordinate.latitude = 20.516700; 
theCoordinate.longitude = 99.900000; 

MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(theCoordinate, 1000, 1000); 
MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:viewRegion]; 
[self.mapView setRegion:adjustedRegion animated:YES]; 
+1

不...同樣的結果:中國的中部。 – coopersita

+0

嘗試改變緯度,經度 –

+0

這樣做。我曾經給我的位置的長和緯度的服務給了我錯誤的價值...... – coopersita