MapKit 和 CoreLocation

    实战应用

 1.首先导入两个包 MapKit.framework 和 CoreLocation.framework.

// 1. 实例化定位管理器

_locationManager = [[CLLocationManager alloc] init];

// 2. 设置代理

_locationManager.delegate = self;

// 3. 定位精度

[_locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

// 4. 更新用户位置

[_locationManager startUpdatingLocation];

•当用户的位置发生改变时,就会不断调用代理方法,比如

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

•当定位失败时,会调用

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error

posted @ 2014-02-22 20:06  好好先堔  阅读(215)  评论(0编辑  收藏  举报