定位相关-CLLocationManager的使用。
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
@interface ViewController ()<CLLocationManagerDelegate> @property(nonatomic,strong)CLLocationManager * manager;
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; }
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
// 1.创建位置管理器 搞全局属性,移动要搞全局属性,否则无法使用位置管理器。
self.manager = [CLLocationManager new];
if ([self.manager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
// 2.请求授权:用户使用的时候授权,配置plist, 一般要写,增加成功几率。
// 用户使用的时候请求,大部分都只要执行这个就行了。
[self.manager requestWhenInUseAuthorization]; // 3.一直允许
// [self.manager requestAlwaysAuthorization];
} // 4.设置代理
self.manager.delegate = self; // 4.开始定位
[self.manager startUpdatingLocation]; // 6.设置位置筛选,为了持续定位,少耗电,弄个属性,当位置改变之后再定位 // 值为10.就代表位置变化超过十米再调动代理方法。(以米为单位的)此方法不打开就是一只调用代理方法。
// self.manager.distanceFilter = 10; // 设置精准度 desiredAccuracy 精准度。
// 定位:
// GPS 跟24颗卫星通讯。
// 北斗 基站 Wi-Fi
// kCLLocationAccuracyBest (Xcode7之前这个值是默认的)
// kCLLocationAccuracyThreeKilometers 这个省电(当对位置的需求不是非常精确的)
// self.manager.desiredAccuracy =kCLLocationAccuracyThreeKilometers; // 允许后台更新位置。需要配置plist,设置成功后屏幕上方会有蓝条,提示次程序正在定位。
// self.manager.allowsBackgroundLocationUpdates = YES;
} -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{ //CLLocationCoordinate2D coordinate 经纬度
//CLLocationDegrees latitude 纬度
//CLLocationDegrees longitude 经度
// 位置对象
CLLocation * location = locations[]; NSLog(@"%@",location);
// 停止定位
[self.manager stopUpdatingHeading]; }
@end
定位相关-CLLocationManager的使用。的更多相关文章
- 百度地图API示例之添加定位相关控件
代码 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" cont ...
- 使用Xpath定位元素(和元素定位相关的Xpath语法)
本文主要讲述Xpath语法中,和元素定位相关的语法 第一种方法:通过绝对路径做定位(相信大家不会使用这种方式) By.xpath("html/body/div/form/input" ...
- 安卓弹出键盘隐藏fixed定位相关的元素(obj必须是class)
//安卓弹出键盘隐藏fixed定位相关的元素(obj必须是class) function displayFixed(obj){ var h = document.body.scrollHeight; ...
- CSS基础 定位相关属性的使用方法
1.相对定位:position:relative: 属性名:position 属性值:relative: 特点:1.相对自己的位置移动 2.配合方位名词移动,如:top.left.right,bott ...
- css里涉及到定位相关的example实例
一,情景导入:正常文档流:指的是HTML文档在进行内容布局时所遵循的从左到右,从上到下的表现方式.HTML中的大多数元素都处在正常的文档流中,而一个元素要脱离正常流的唯一途径就是浮动或定位.二,定位的 ...
- CSS 定位相关属性 :position
我们平时经常用margin来进行布局,但是遇到一些盒子不规律布局时,用margin就有点麻烦了,这个时候我们可以用position. position:参数 参数分析: 一.absolute: 相对父 ...
- Position定位相关知识了解
一.定位 position属性 1.默认定位: position:static; 元素框正常生成.块级元素生成一个矩形框,作为文档流的一部分,行内元素则会创建一个或多个行框,置于其 ...
- CSS - 定位相关
定位 (position) 1. 相对定位 (relative) 相对于元素原来的位置进行移动 2. 绝对定位 (absolute) 如果父级元素中有相对定位属性, 则参照父级元素进行定位, 默认参照 ...
- QTL定位相关
1.原理 https://www.sohu.com/a/211301179_278730 较为详细
随机推荐
- yarn环境的搭建
1.首先,在zookeeper搭建成功,服务运行的基础上搭建yarn,其次,保证时间一致 2.在 /home/install/hadoop-2.5/etc/hadoop目录下配置一下几个配置文件: 第 ...
- 【HTML】Intermediate6:Text: Addresses, Definitions, Bi-directional, and Editorial
1.</address> It should be used specifically for the contact details relating either to the ent ...
- 【原创】MapReduce编程系列之表连接
问题描述 需要连接的表如下:其中左边是child,右边是parent,我们要做的是找出grandchild和grandparent的对应关系,为此需要进行表的连接. Tom Lucy Tom Jim ...
- 解决Hadoop-Eclipse-Plugin放在Plugin目录下没反应的问题
有时候自己编译或者下载的Hadoop-Eclipse-Plugin放到Eclipse的Plugin目录下面,启动Eclipse没有反应,即看不到小象和Map/Reduce视图.可以通过查看Eclips ...
- Recommended add-ons/plugins for Microsoft Visual Studio [closed]
SmartPaster - (FREE) Copy/Paste code generator for strings AnkhSvn - (FREE) SVN Source Control Integ ...
- CodeForces 352C. Jeff and Rounding(贪心)
C. Jeff and Rounding time limit per test: 1 second memory limit per test: 256 megabytes input: stan ...
- 【python自动化第十篇:】
复习: 线程与进程的区别: 进程:资源的集合 线程:最小调度单位 进程至少包含一个线程 线程之间的内存是共享的,两个线程操作同一个数据就会修改整个结果(需要mutex加锁来保持数据的一致性),递归锁, ...
- chrome浏览器当表单自动填充时,怎么去除浏览器自动添加的默认样式。
参考blog来自 http://segmentfault.com/q/1010000000671971 chrome浏览器当表单自动填充时,怎么去除浏览器自动添加的默认样式. 一.发现该问题的原因-是 ...
- ListBox基础
关键点 在列表框生成后需要向其中加入或是删除行,可以利用: int AddString( LPCTSTR lpszItem )添加行, int DeleteString( UINT nIndex ...
- [Angular 2] Handle Reactive Async opreations in Service
When you use ngrx/store and you want to fire a service request. When it sucessfully return the respo ...