2012-08-11 78 views
0

我添加了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 

回答

0
CLLocation 

是一個位置對象,它包含一個特定的座標/位置,可以顯示在地圖視圖上。但是,CLLocationManager是管理位置和航向更新的對象。 setDesiredAccuracy是您設置位置經理位置和標題更新的準確性的方法。如果您將準確度設置得很高,位置管理員將會更新一個非常準確的位置,但相當慢。 (不是真的,但是當你比較其他準確性時)。

的委託方法,其中的位置更新它:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 

要開始更新,你可以先定製,就像你說的,在準確性和距離過濾器。然後開始,簡單地寫:

[locationManager startUpdatingLocation]; 

而且,所以我可以猜測你將如何停止更新。

注意:如果你在ARC上,讓你的位置管理器成爲一個實例變量(在.h中聲明),因爲它很快釋放位置管理器,並且彈出讓用戶決定你的應用程序是否可以跟蹤你的位置然後在不到一秒鐘內消失。當然你的位置不會更新。

3

你想CLLocationManager,不CLLocation

3

我想你想使用CLLocationManager ...

CLLocationManager *locationManager; 
相關問題