#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
{
}
答案 0 :(得分:1)
当地点发生变化时,系统会调用didUpdateToLocation
。
我猜你是在模拟器中测试它,在模拟器上没有发生位置变化所以方法没有调用。
Suggesstion 您应该实施other delegate methods来检查发生的事情;如果有错误的话。例如:locationManager:didFailWithError: