博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS原生定位和反编码
阅读量:6865 次
发布时间:2019-06-26

本文共 1134 字,大约阅读时间需要 3 分钟。

  hot3.png

经常碰到需要获取当前地址的需求,iOS原生方法就可以解决。

导入头文件

#import <CoreLocation/CoreLocation.h>

(nonatomic, strong) CLLocationManager *lcManager

开始请求定位

if ([CLLocationManager locationServicesEnabled]) { // 创建位置管理者对象 self.lcManager = [[CLLocationManager alloc] init];self.lcManager.delegate = self; // 设置代理 // 设置定位距离过滤参数 (当本次定位和上次定位之间的距离大于或等于这个值时,调用代理方法) self.lcManager.distanceFilter = 100;self.lcManager.desiredAccuracy = kCLLocationAccuracyBest; // 设置定位精度(精度越高越耗电)[self.lcManager requestWhenInUseAuthorization];//这句很关键!!![self.lcManager startUpdatingLocation]; // 开始更新位置}else{ //没开启,做其他提醒 }

代理:CLLocationManagerDelegate

代理方法: `

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{NSLog(@"定位到了");CLGeocoder *geocoder = [[CLGeocoder alloc]init];[geocoder reverseGeocodeLocation:[locations firstObject] completionHandler:^(NSArray
*_Nullable placemarks, NSError * _Nullable error) { CLPlacemark *place = [placemarks firstObject]; //place包含了地理信息}];}-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{NSLog(@"获取定位失败");}

转载于:https://my.oschina.net/yup/blog/3035286

你可能感兴趣的文章
Spring 中的 context
查看>>
重构代码(应如写诗)
查看>>
Vue混入mixins
查看>>
前阿里 P9 级员工称离婚是模拟测试,已回滚复婚!
查看>>
衡阳a货翡翠,南平a货翡翠
查看>>
大姨太入场,EtcGame全线升级为Coingame,开启ETH投注倒计时……
查看>>
阿里云HBase推出全新X-Pack服务 定义HBase云服务新标准
查看>>
通过Auto Layout深入了解SizeClasses的好处和使用
查看>>
Spring scope解惑
查看>>
BCH与BCE共享比特币之名
查看>>
js脚本 处理js注入
查看>>
A potentially dangerous Request.Form value was detected from the client
查看>>
测试过程之过分关注功能性测试
查看>>
SQL Server -- LIKE模糊查询
查看>>
centos7.0 docker安装部署
查看>>
ORA-32004错误的解决方法
查看>>
嵌入式系统学习步骤
查看>>
PPT | Docker定义存储-让应用无痛运行
查看>>
django 自定义日志配置
查看>>
是程序员,就用python导出pdf
查看>>