我正在尝试使用distanceFromLocation:方法来计算我手里拿着iPhone走的总距离.到目前为止,我一直在寻找帮助解决我混乱,不准确和看似随意的结果.在这些代码片段中,theLabel只是我的应用程序界面中的标签对象,distanceMoved是我试图存储我走进的总距离的变量,locMan是在我的@interface文件中声明的位置管理器.
- (void)viewDidLoad
{
locMan = [[CLLocationManager alloc] init];
locMan.delegate = self;
[locMan startUpdatingLocation];
isInitial = true;
distanceMoved = 0.0;
[super viewDidLoad];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
distanceMoved += [newLocation distanceFromLocation: oldLocation];
theLabel.text = [NSString stringWithFormat: @"%f meters", distanceMoved];
}
Run Code Online (Sandbox Code Playgroud)
任何有助于解决我在这里做错的帮助将不胜感激.谢谢!
我正在尝试使用新的iOS 6功能的自定义位置更新,但继续收到此错误:
didFinishDeferredUpdatesWithError:Error Domain = kCLErrorDomain Code = 11"无法完成操作.(kCLErrorDomain error 11.)"
我使用以下代码:
- (DeviceAPI *) init
{
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
[locationManager allowDeferredLocationUpdatesUntilTraveled:(CLLocationDistance)100000 timeout:(NSTimeInterval)100000];
return self;
}
Run Code Online (Sandbox Code Playgroud)
而这个callback
功能:
- (void)locationManager: (CLLocationManager *) manager
didFinishDeferredUpdatesWithError:(NSError *)error
{
NSLog(@"didFinishDeferredUpdatesWithError :%@", [error description]);
}
Run Code Online (Sandbox Code Playgroud)
有帮助吗?