获取GPS中的当前位置?

时间:2010-10-25 12:58:49

标签: iphone

以下是我的代码但不起作用。任何人都可以帮助我吗?

- (void)viewDidLoad {
    [super viewDidLoad];

   CLController = [[CoreLocationController alloc] init];
   CLController.delegate = self;
   //[CLController setDesiredAccuracy:kCLLocationAccuracyBest]; 
   [CLController.locMgr startUpdatingLocation];
}

- (void)locationUpdate:(CLLocation *)location {
   locLabel.text = [location description];
}

- (void)locationError:(NSError *)error {
   locLabel.text = [error description];
}

1 个答案:

答案 0 :(得分:0)

您没有正确执行CLocationManager委托方法

(void)locationUpdate:(CLLocation *)location {
   locLabel.text = [location description]; 
 }

应该是

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation     *)newLocation fromLocation:(CLLocation *)oldLocation{
 locLabel.text = [newLocation description];
}

在实施之前,您应该仔细阅读Apple的文档http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManagerDelegate_Protocol/CLLocationManagerDelegate/CLLocationManagerDelegate.html%23//apple_ref/doc/uid/TP40007124