zoukankan      html  css  js  c++  java
  • ios 苹果原生系统定位 CLLocationManager

     首先要干这些事

     下面的方法亲测可用

     ------------------------------------------------------------

        DNLogFUNC

        //初始化位置管理对象

        _locationManager = [[CLLocationManager alloc] init];

        //请求用户授权

        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {

            [_locationManager requestWhenInUseAuthorization];

        }

        //指定定位代理类

        _locationManager.delegate = self;

        _locationManager.distanceFilter = 100;

        //开启定位服务

        [_locationManager startUpdatingLocation];

    #pragma  mark ----  CLLocationManagerDelegate

    //定位成功  位置更新回调 的协议方法

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

    {

        

        CLLocation *currentLocation = [locations lastObject];

        

        CLLocationCoordinate2D coor = currentLocation.coordinate;

        //维度

        DNLog(@"coor.latitude==%f",coor.latitude);

        //经度

        DNLog(@"coor.longitude==%f",coor.longitude);

    //    //地理编码类

    //    CLGeocoder *geocoder = [[CLGeocoder alloc] init];

    //    //反编码  经纬度点-->地理位置信息

    //    [geocoder reverseGeocodeLocation:[locations lastObject] completionHandler:^(NSArray *placemarks, NSError *error) {

    //        if (!error) {

    //            //取最后一个地址

    //            CLPlacemark *placemark = [placemarks lastObject];

    //           NSString *cityStr = [NSString stringWithFormat:@"%@",placemark.locality];

    ////            DNLog(@"cityStr==%@",cityStr);取出定位城市

    //            DNLog(@"placemark==%@",placemark.addressDictionary);

    //             DNLog(@"placemarks==%@",placemarks);

    //

    //        }

    //    }];

    }

  • 相关阅读:
    nginx面试题
    解决zabbix图形显示“方块”问题
    echo命令详解
    Ubantu1804更换阿里源
    arp命令
    /boot、/和/swap分区扩容
    windows server 2016 安装 .Net Framework失败解决方案
    报错kernel:NMI watchdog: BUG: soft lockup
    jenkins 常用插件源URL
    jenkins rpm包方式安装
  • 原文地址:https://www.cnblogs.com/soulDn/p/5664052.html
Copyright © 2011-2022 走看看