Graphics Programs Reference
In-Depth Information
Core Location
The Core Location framework contains the classes that enable applications to determine the
device's geographical location. No matter what type of iOS device is being used, the Core
Location code you write does not change.
In addition to adding the Core Location framework to your target, you also have to import
the framework's header file into files that need to know about Core Location classes. Every
framework has a header file that imports the header file of every class in that framework.
This file is always the name of the framework suffixed with .h .
Open WhereamiViewController.h and import the Core Location header file at the
top. Also, add an instance variable to hold a pointer to an instance of CLLocationMan-
ager - one of the classes in the Core Location framework.
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface WhereamiViewController : UIViewController
{
CLLocationManager *locationManager;
}
@end
CLLocationManager is the class that interfaces with the location hardware of the
device. An instance of CLLocationManager has a number of properties that specify its
behavior. We're going to set one of them: desiredAccuracy .
The desiredAccuracy property tells the location manager how accurate the location-
finding should be. This is important because there is a tradeoff between the accuracy of the
location and the amount of time and battery life required to determine the location.
Moreover, the accuracy ultimately depends on the type of device the user has, the availabil-
ity of cellular towers and satellites, and the availability of known wireless access points.
Open WhereamiViewController.m and delete all of the code between @imple-
mentation and @end . The file should now look like this:
#import "WhereamiViewController.h"
@implementation WhereamiViewController
@end
Now in WhereamiViewController.m , override initWithNibName:bundle: to
instantiate a CLLocationManager , set the desiredAccuracy to request the most
Search WWH ::




Custom Search