background image

@property(nonatomic, strong) CLLocationManager *locationManager;

@end

        在 h 文 件 中 首 先 需 要 引 入 <CoreLocation/CoreLocation.h>   和
<CoreLocation/CLLocationManagerDelegate.h>头文件。然后在定义 ViewController 时需要声
明 实 现 CLLocationManagerDelegate

 

协 议 。 我 们 还 定 义 了

CLLocationManager 

*locationManager 属性。

    ViewController.m 的 viewDidLoad 代码如下:

- (void)viewDidLoad

{

[super viewDidLoad];

//定位服务管理对象初始化

_locationManager = [[CLLocationManager alloc] init];

_locationManager.delegate = self;

_locationManager.desiredAccuracy = kCLLocationAccuracyBest; ①