Hey guys, I'm trying to call the update method but its not working, any idea?
#import "TrackerViewController.h"
@implementation TrackerViewController
-(IBAction)updateButton:(id)sender{
[self update];
}
-(void)update{
locmanager = [[CLLocationManager alloc] init];
[locmanager setDelegate:self];
[locmanager setDesire开发者_高级运维dAccuracy: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
{
}
The didUpdateToLocation
will be called when an location changes.
I guess you are testing it in simulator and on simulator no change occurs in location so the method don't called.
Suggesstion You should implement other delegate methods to check whats happening; in case if there is some error. For example: locationManager:didFailWithError:
精彩评论