【发布时间】:2022-04-10 02:44:56
【问题描述】:
我正在尝试在用户摇动他的 iPhone 时获取位置更新,我在接收到摇动事件时启用 GPS,但我的问题是未调用 didUpdateToLocation 方法。谁能告诉我我的代码有什么问题?
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if(event.type == UIEventSubtypeMotionShake)
{
[self first];
}
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// NSLog(@"OldLocation %f %f", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
// NSLog(@"NewLocation %f %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
NSString * currentLat = [NSString stringWithFormat:@"%f",newLocation.coordinate.latitude];
NSLog(@"currentLat%@",currentLat);
NSString * currentLong = [NSString stringWithFormat:@"%f",newLocation.coordinate.longitude];
NSLog(@"currentLong%@",currentLong);
}
-(void)first
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
NSLog(@"called");
[self.view setBackgroundColor:[UIColor greenColor]];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self becomeFirstResponder];
}
【问题讨论】:
标签: ios core-location