2013-05-19 42 views
0

我有一個應用程序顯示用戶的位置的經度和緯度。應用程序詢問當前位置,並在Xcode中顯示緯度和經度。但在應用程序中,沒有任何反應。位置管理器將不會顯示經度和緯度

這裏是我的代碼:

- (NSString *)deviceLocation { 
    NSString *theLocation = 
     [NSString stringWithFormat:@"latitude: %f longitude: %f", 
     locationManager.location.coordinate.latitude, 
     locationManager.location.coordinate.longitude]; 
    return theLocation; 
} 

在viewDidLoad中:

locationManager = [[CLLocationManager alloc] init]; 
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move 
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m 
[locationManager startUpdatingLocation]; 

NSLog(@"%@", [self deviceLocation]); 

的問題是,緯度和經度-labels不會顯示的位置。

+0

@MichaelDautermann,這是我唯一的代碼。 –

+0

我認爲問題是我沒有設置我的標籤與位置管理器一起工作。你能幫我解決這個問題嗎? –

回答

0

我的猜測是你沒有將你的視圖控制器作爲委託人分配給CLLocationManager。

你可以做到這一點通過:

locationManager.delegate = self; 

您創建的LocationManager之後。

然後,您可以通過讓視圖控制器響應委託方法locationManager:didUpdateLocations:來更新標籤。