我想从我的代码连接到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位置继续操作该屏幕。
在ViewDidLoad
方法MainScreenViewController
我写了以下;
- (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
方法。那么我怎样才能得到这些价值呢?
那么你说'ViewDidLoad'后,'locationUpdate'被调用?并在调用ViewDidLoad后不退出? – sharon
您需要实现在应答中复制的协议,此方法仅在GPS获取新坐标时才会更新。 – gfdgfd
你是什么意思?我是新手:S请你详细说明 – sharon