首页 > 其他 > 详细

CoreLoation

时间:2015-04-08 19:37:36      阅读:210      评论:0      收藏:0      [点我收藏+]
- (CLLocationManager *)locationManager
{
    if (!_locationManager) {
        _locationManager = [[CLLocationManager alloc] init];
        _locationManager.delegate = self;
        _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        _locationManager.distanceFilter = 10;
        [_locationManager requestAlwaysAuthorization];//添加这句
    }
    return _locationManager;
}

#pragma mark - CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    debugMethod();
    CLLocation *currentLocation = [locations lastObject];
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        CLPlacemark *placemark = [placemarks firstObject];
        
    }];
    
    //关闭定位服务
    [self.locationManager stopUpdatingLocation];
}


#pragma mark - IBAction

//定位按钮被点中
- (IBAction)locationBtnDidClick:(id)sender {
    debugMethod();
    if([CLLocationManager locationServicesEnabled]) {
        [self.locationManager startUpdatingLocation];
    } else {
        [self.tableView makeToast:@"请打开定位服务" duration:1.0 position:@"center"];
    }
}


info.plist中加入两行:
NSLocationAlwaysUsageDescription : 点击"允许"以开启云买手定位服务
NSLocationWhenInUseDescription :  点击"允许"以开启云买手定位服务

 

CoreLoation

原文:http://www.cnblogs.com/apem/p/4403091.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!