2010-10-25 192 views
2

下面是我的代码,但它不工作。谁能帮我???在GPS中获取当前位置?

- (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]; 
} 

回答

0

你不是做CLocationManager委托方法正确

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

应该

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

你应该实现它之前仔细阅读苹果公司对本文档http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManagerDelegate_Protocol/CLLocationManagerDelegate/CLLocationManagerDelegate.html%23//apple_ref/doc/uid/TP40007124