NSLocationWhenInUseUsageDescription和NSLocationAlwaysUsageDescription
//导入头文件
#import <CoreLocation/CoreLocation.h>
if
(![CLLocationManager
locationServicesEnabled])
{
return;
}
self.mgr=
[[CLLocationManager
alloc]
init];
[self.mgr
requestWhenInUseAuthorization];
// 设置移动多少米,定位一次
_mgr.distanceFilter = 50;
// 设置定位精度
_mgr.desiredAccuracy = kCLLocationAccuracyBest;
// 设置CLLocationManager的代理,来获取用户的位置
_mgr.delegate = self;
//代理方法 现实用户位置
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
// 取出用户的位置信息
CLLocation *location = [locations lastObject];
CLLocationCoordinate2D coordinate = location.coordinate;
NSLog(@"纬度:%f 经度:%f", coordinate.latitude, coordinate.longitude);
//停止定位
[manager stopUpdatingLocation];
}