开发者

obtaining current location in GPS?

开发者 https://www.devze.com 2023-01-21 16:14 出处:网络
Below is my code but its not working. Can anyone help me??? - (void)viewDidLoad { [super viewDidLoad]; CLController = [[CoreLocationController alloc] init];

Below is my code but its not working. Can anyone help me???

- (void)viewDidLoad {
    [super viewDidLoad];

   CLController = [[CoreLocationController alloc] init];
   CLController.delegate = self;
   //[CLController setDesiredAccuracy:kCLLocationAccuracyBest]; 
   [CLController.locMgr startUpdatingLocation开发者_StackOverflow社区];
}

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

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


You aren't doing the CLocationManager delegate methods properly

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

Should be

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

You should read Apple's documentation http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManagerDelegate_Protocol/CLLocationManagerDelegate/CLLocationManagerDelegate.html%23//apple_ref/doc/uid/TP40007124 about this thoroughly before implementing it.

0

精彩评论

暂无评论...
验证码 换一张
取 消