zoukankan      html  css  js  c++  java
  • CoreLoation

    - (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 :  点击"允许"以开启云买手定位服务
  • 相关阅读:
    事件基础
    Event loop 事件的循环和为什么使用函数
    Promise 对象---异步调用
    新版博客园分类不能正常显示
    OpenCV学习
    c# 常用正则
    C#调用OpenCV——美图效果
    WPF中的Image控件Source的设置(包括直接读取图片文件的代码)
    图像处理的灰度化和二值化
    C#弹出U盘
  • 原文地址:https://www.cnblogs.com/apem/p/4403091.html
Copyright © 2011-2022 走看看