已更新iOS9:我是iOS新手,嘗試使用CoreLocation返回經度和緯度值。下面的代碼永遠不會執行日誌輸出經緯度未找回
-(void)viewWillAppear:(BOOL)animated{
manager = [[CLLocationManager alloc]init];
manager.delegate = self;
manager.desiredAccuracy = kCLLocationAccuracyBest;
[manager startUpdatingLocation];
}
這裏是我的永遠達不到
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray<CLLocation *> *)locations{
NSLog(@"Location: %@", locations);
CLLocation *currentLocation = locations.lastObject;
if (currentLocation != nil) {
float latitude = currentLocation.coordinate.latitude;
float longitude = currentLocation.coordinate.longitude;
NSLog(@"dLongitude : %f", longitude);
NSLog(@"dLatitude : %f", latitude);
}
else{ NSLog(@"ERROR");
}
}
使用實際的設備,而不是模擬器 –
需要實現'CLLocationManager'委託提供你拉長信息。你不能直接得到它。有關更多詳細信息,請參閱[蘋果文檔](https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManagerDelegate_Protocol/index.html) –
@ sam-b我在設備上測試,我也更新了我的代碼爲iOS 9並且仍然有問題 – themotjuste