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);
//
// }
// }];
}
最新文章
- iOS保存cookie的方法
- location.hash的摘抄
- Directory的GetFiles方法
- ios app 支持 ipv6-only
- 你早该这么玩Excel 读书笔记
- 分布式发布订阅消息系统 Kafka 架构设计[转]
- mysql 的 decimal类型
- 使用form的target属性屏蔽url跳
- 记录近期小改Apriori至MapReduce上的心得
- oracle存储过程的基本语法
- EBS各个应用简称
- 加载静态界面----,要不要会加载cookie和页面参数
- lodash源码分析之去重--uniq方法
- HTTP 错误 500.21 - Internal Server Error 处理程序“BlockViewHandler”在其模块列表中有一个错误模块“ManagedPipelineHandler
- FFmpeg数据结构AVFrame
- 将 Azure VM 迁移到 Azure 中的托管磁盘
- 注意JDBC驱动的版本和JDK的版本是否匹配 JDBC连接Mariadb
- Tomcat无法访问中文路径的解决办法
- 最优比率生成树 POJ 2728 迭代或者二分
- hdoj1176 免费馅饼(dp 数塔)
热门文章
- i2c_set_clientdata函数【转】
- HDU3613 Best Reward —— Manacher算法 / 扩展KMP + 枚举
- Centos7.2——自定义系统服务
- 以太坊EVM1.0缺陷
- servlet的<;url-pattern>;
- 【NOIP2017 DAY1T2】 时间复杂度
- 高可用性和PyMongo
- bzoj 4260 REBXOR —— Trie树
- kubernetes1.13.1部署ingress-nginx-十一
- 洛谷 - P5000 - Hillwer编码 - 高精度