IOS-corelocation
来源:互联网 发布:javascript设计模式pdf 编辑:程序博客网 时间:2024/06/05 19:31
尽管有很多的第三方框架用于定位,但是都是建立在苹果的corelocation的基础之上的。
刚刚学习了corelocation,在此就记录一下。
第一步:你要导入CLLocationManager头文件
第二步:拥有CLLocationManager对象(进行懒加载即可)
- (CLLocationManager *)mgr{ if(!_mgr){ _mgr = [[CLLocationManager alloc] init]; } return _mgr;}
设置mgr的代理,遵守协议
self.mgr.delegate = self;
第三步:主动请求,要求用户授权
调用对象方法
[mgr requestAlwaysAuthorization] //始终[mgr requestWhenInUseAuthorization] //可见
然后在info文件中添加NSLocationAlwaysUsageDescription/NSLocationWhenInUsesDescription(始终/可见)项。
第四步:授权状态改变通知代理方法,成功后开始监听
(CLLocationManager*)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{ /* // CLAuthorizationStatus 用户从未选择过权限 kCLAuthorizationStatusNotDetermined 无法使用定位服务,该状态用户无法改变 kCLAuthorizationStatusRestricted 用户拒绝该应用使用定位服务,或是定位服务总开关处于关闭状态 kCLAuthorizationStatusDenied 已经授权(废弃) kCLAuthorizationStatusAuthorized 用户允许该程序无论何时都可以使用地理信息 kCLAuthorizationStatusAuthorizedAlways 用户同意程序在可见时使用地理位置 kCLAuthorizationStatusAuthorizedWhenInUse */ if(status == kCLAuthorizationStatusAuthorizedWhenInUse ||kCLAuthorizationStatusAuthorizedAlways){ [mgr startUpdatingLocation]; }}
第五步:调用监听代理方法
didUpdateLocation;
在代理方法的参数中,locations是location对象的数组,location对象包含了各种经纬度,海拔高度,时间等等的信息
方向
获取方向的值调用的是
[mgr startUpdatingHeading]
magneticHeading 设备与磁北的相对角度(常用)
trueHeading 与真北的角度
区域监听(同样需要主动请求)
第一步,创建区域(CLRegion有两个子类是专门用于指定区域的:一个蓝牙范围/一个是指定圆形范围)
CLCircularRegion 指定圆形范围(常用)
第二部,开始监听
[mgr startMonitoringForRegion:(CLRegion *)];
调用代理方法
didEnterRegion/didExitRegion;(进入/离开)
地理编码
地理编码(根据位置信息,获取各种该位置的具体地理信息)
相关的对象时CLGeocoder
调用的对象方法是 geocoderAddressstring
反地理编码:根据给定的经纬度,获得具体的位置信息
调用的对象方法是reverseGeocodeLocation,传参是一个CLLocation对象。
第三方框架
推荐一个用于定位的第三方框架
INTULocationManager:https://github.com/intuit/LocationManager
- IOS CoreLocation
- IOS CoreLocation
- IOS CoreLocation
- IOS-corelocation
- iOS 定位 <CoreLocation/CoreLocation.h>
- iOS定位服务CoreLocation
- iOS CoreLocation的使用
- iOS CoreLocation地理编码
- iOS定位--CoreLocation
- iOS 使用CoreLocation定位
- CoreLocation IOS 定位详解
- iOS-使用CoreLocation定位
- iOS定位服务 CoreLocation
- iOS CoreLocation框架 定位
- iOS开发CoreLocation框架
- iOS 地图CoreLocation定位
- iOS定位-CoreLocation 记录
- iOS CoreLocation定位 使用方法
- 2016.8.17日记
- [SCU 4437 Carries] 二分
- 各种实用的模板和黑科技(缓更)
- 14All configured PGW endpoint service URIs are unusable.
- 数据结构实验之图论六:村村通公路
- IOS-corelocation
- ccf字符串题
- js操作cookie
- 【BZOJ3555】企鹅QQ,第一次正确的使用哈希A题
- 数组排序 —— 常见排序练习题(有序矩阵查找、最短子数组)
- 【bzoj 4547】【Hdu 5171】小奇的集合(找规律+矩阵快速幂)
- 51nod 1491 黄金系统
- FOJ有奖月赛-2016年8月 Problem A Daxia & Wzc's problem(找规律)
- 8-17比赛总结