I added the CoreLocation framework, and I keep rereading the code in my book to make sure I copied it down correctly but I am getting a persistent No visible @interface for 'CLLocation' declares the selector 'setDesiredAccuracy:' error.
#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
is a location object, it holds a specific coordinate/location, that can be displayed on a map view. However,
CLLocationManageris an object which manages location and heading updates.setDesiredAccuracyis the method where you set the accuracy of the location manager’s location and heading updates. If you set the accuracy high, the location manager will update with a very accurate point of where you are, but considerably slow. (Not really, but when you compare to other accuracies).The delegate method where the location updates it:
To start the updates, you can first customize it like you said, with the accuracy and distance filter. Then to start, simply write:
And, so I can guess how you would stop updates.
NOTE: If you are on ARC, make your location manager an instance variable (declared in .h) because it releases the location manager very quickly and the popup to let the user decide if your app can track you location will popup and then disappear in less than a second. And of course your locations wont update.