我尝试实时更新设备的位置课程。
我正在做一些实验,我将VC作为CLLocationManager的委托。但是当我运行应用程序时,课程信息根本没有更新。我确实在委托设置行中设置了断点,但位置管理器在调试区域中为零。
有什么问题?
#import "CourseInfomationViewController.h"
@interface CourseInfomationViewController ()
- (IBAction)startMoveLocation:(id)sender;
@end
@implementation CourseInfomationViewController
{
CLLocationManager *_locationManager;
CLLocation *_deviceLocation;
double _deviceDirection;
double _altitude;
double _speed;
}
-(id)init {
if (self = [super init]) {
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
//
_deviceLocation = [[CLLocation alloc] init];
}
return self;
}
- (IBAction)startMoveLocation:(id)sender {
[_locationManager startUpdatingLocation];
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - location Delegate
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
_deviceLocation = [locations lastObject];
_altitude = _deviceLocation.altitude;
_deviceDirection = _deviceLocation.course;
_speed = _deviceLocation.speed;
NSLog(@"altitude is %f", _altitude);
NSLog(@"altitude is %f", _deviceDirection);
NSLog(@"altitude is %f", _speed);
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"%@", error);
}