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);

    //

    //        }

    //    }];

    }

  • 相关阅读:
    Hibernate: Encountered a duplicated sql alias [] during auto-discovery of a native-sq
    “Uncaught TypeError: string is not a function”
    Jquery Ajax 返回数据类型变成document
    浏览器URL编码
    SQL Server 多条查询结果组合
    (转)No row with the given identifier exists问题的解决
    观nginx与lvs负载均衡的较量
    Nginx启动、关闭、重新加载脚本
    数据挖掘-分词入门
    HBase 专题技术收录
  • 原文地址:https://www.cnblogs.com/soulDn/p/5664052.html
Copyright © 2011-2022 走看看