'CLLocation'没有可见的@interface声明选择器'setDesiredAccuracy:'
问题描述:
我添加了CoreLocation框架,并且不断重读我书中的代码以确保我将它正确地复制下来,但是我得到持续的No visible @interface for 'CLLocation' declares the selector 'setDesiredAccuracy:'
错误。'CLLocation'没有可见的@interface声明选择器'setDesiredAccuracy:'
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface WhereamiViewController : UIViewController {
CLLocation *locationManager;
}
@end
#import "WhereamiViewController.h"
@interface WhereamiViewController()
@end
@implementation WhereamiViewController
-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
locationManager = [[CLLocation alloc] init
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
}
return self;
}
@end
答
CLLocation
是一个位置对象,它包含一个特定的坐标/位置,可以显示在地图视图上。但是,CLLocationManager
是管理位置和航向更新的对象。 setDesiredAccuracy
是您设置位置经理位置和标题更新的准确性的方法。如果您将准确度设置得很高,位置管理员将会更新一个非常准确的位置,但相当慢。 (不是真的,但是当你比较其他准确性时)。
的委托方法,其中的位置更新它:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
要开始更新,你可以先定制,就像你说的,在准确性和距离过滤器。然后开始,简单地写:
[locationManager startUpdatingLocation];
而且,所以我可以猜测你将如何停止更新。
注意:如果你在ARC上,让你的位置管理器成为一个实例变量(在.h中声明),因为它很快释放位置管理器,并且弹出让用户决定你的应用程序是否可以跟踪你的位置然后在不到一秒钟内消失。当然你的位置不会更新。
答
你想CLLocationManager
,不CLLocation
。
答
我想你想使用CLLocationManager
...
CLLocationManager *locationManager;