獲取當前位置需要改plist文件 在plist文件加入 NSLocationWhenInUseUsageDescription 字段
/**
初始化一個管理器對象
*/
locationManager = [[CLLocationManager alloc] init];
/**
* 設置代理
*/
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
/**
* 設置移動多遠來獲取一次請求
*/
locationManager.distanceFilter = 1000.0f;
/**
* 判斷版本
*
* @param requestWhenInUseAuthorization
*
* @return ios7以上需要寫此方法來獲取當前位置
*/
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[locationManager requestWhenInUseAuthorization];
}
/**
* 開始獲取當前位置
*/
[locationManager startUpdatingLocation];