方法未被调用(核心位置)Cocoa Touch

时间:2011-03-11 18:28:33

标签: iphone methods sdk call core-location

嘿伙计们, 我正在尝试调用更新方法,但它不起作用,任何想法?

#import "TrackerViewController.h"

@implementation TrackerViewController

-(IBAction)updateButton:(id)sender{
    [self update];
    }

-(void)update{
    locmanager = [[CLLocationManager alloc] init]; 
    [locmanager setDelegate:self]; 
    [locmanager setDesiredAccuracy:kCLLocationAccuracyBest];

    [locmanager startUpdatingLocation];


}


-(void)viewDidLoad {
    [self update];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    CLLocationCoordinate2D loc = [newLocation coordinate];

    latitude.text = [NSString stringWithFormat: @"%f", loc.latitude];
    longtitude.text = [NSString stringWithFormat: @"%f", loc.longitude];


}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 

}

1 个答案:

答案 0 :(得分:1)

当地点发生变化时,系统会调用didUpdateToLocation

我猜你是在模拟器中测试它,在模拟器上没有发生位置变化所以方法没有调用。

Suggesstion 您应该实施other delegate methods来检查发生的事情;如果有错误的话。例如:locationManager:didFailWithError: