Graphics Programs Reference
In-Depth Information
accurate location data as often as possible, and then tell the CLLocationManager to
start working.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Create location manager object
locationManager = [[CLLocationManager alloc] init];
// And we want it to be as accurate as possible
// regardless of how much time/power it takes
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
// Tell our manager to start looking for its location immediately
[locationManager startUpdatingLocation];
}
return self;
}
Once you tell the CLLocationManager to start working, it does its thing while the rest
of the application continues with other tasks - like accepting user input or updating the in-
terface.
Receiving updates from CLLocationManager
If you build and run this code right now, the location manager will get your current loca-
tion, but you won't see this information anywhere. Your application has to retrieve the
location from the location manager. You might guess that there is a property on CLLoca-
tionManager called currentLocation that we can access to retrieve the location.
It's a good guess, but there isn't.
Instead, whenever the location manager finds the current location, it sends the message
locationManager:didUpdateToLocation:fromLocation: to its delegate .
What object is the location manager's delegate? We get to decide.
Every CLLocationManager has a delegate property, and we can set this property
to point to the object that we want to receive the “location found” message. For Where-
ami , this object is the WhereamiViewController ( Figure 4.4 ).
Figure 4.4 Whereami object diagram
 
Search WWH ::




Custom Search