【发布时间】:2011-10-24 16:38:14
【问题描述】:
我正在尝试从我的代码连接到 GPS。我是按照to this tutorial 这样做的。
- (void)viewDidLoad {
[super viewDidLoad];
CLController = [[CoreLocationController alloc] init];
CLController.delegate = self;
[CLController.locMgr startUpdatingLocation];
}
- (void)locationUpdate:(CLLocation *)location {
locLabel.text = [location description];
}
- (void)locationError:(NSError *)error {
locLabel.text = [error description];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
上面的代码放在一个叫做GetMyLocationViewController的视图控制器中,我还有另一个叫做MainScreenViewController的视图控制器。
当屏幕加载时,MainScreenViewController 被加载,我需要 GPS 位置才能继续使用此屏幕进行操作。
在MainScreenViewController的ViewDidLoad方法中我写了以下内容;
- (void)viewDidLoad {
[super viewDidLoad];
GetMyLocationViewController *getMyLocationViewController = [[GetMyLocationViewController alloc]initwithXib:nil bundle:nil];
[self.navigationController pushViewController:getMyLocationViewController Animation:YES];
// AND THEN I NEED TO ACCESS THE LONGITUDE AND LATITUDE VALUES
}
当上面的代码被执行时,MainScreenViewController 的viewDidLoad 方法被执行,而不是locationUpdate 方法。我可以获得longitude 和latitude 的值的唯一方法是执行locationUpdate 方法。那么如何获取这些值呢?
【问题讨论】:
标签: iphone objective-c ios cocoa-touch core-location