2010-10-25 185 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