CLLocationManagerDelegate的解说
1、//新的方法。登陆成功之后(旧的方法就无论了)
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray<CLLocation *> *)locations
//locationManager:didUpdateLocations:(调用非常频繁)
//更新位置的方法之后就调用这种方法,数组中是依照时间的先后顺序,即为将旧的和新的位置放在数组中
2、//与之相应的 登陆失败之后的调用。定位失败了之后
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error;
问题1、
发现有的时候更新位置的时候我们停止了对应的更新方法,可是还是打印出两个或者三个更行的位置。
2015-08-14 17:23:09.285 mylocation[450:209668] location is :<+22.52849988,+113.93162929> +/- 65.00m (speed -1.00 mps / course -1.00) @ 15/8/14 中国标准时间下午5:23:08
2015-08-14 17:23:09.285 mylocation[450:209668] location is :<+22.52849988,+113.93162929> +/- 65.00m (speed -1.00 mps / course -1.00) @ 15/8/14 中国标准时间下午5:23:08
更新的代码为:
#pragma mark CLLocationManagerDelegate
//定位成功
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *location = [locations lastObject];
NSLog(@" location is :%@ ",location.description);
[self.locationManager stopUpdatingLocation];
}
那是由于,我们将 [self.locationManager stopUpdatingLocation];放在了输出对应的信息之后。当我们停止定位的时候须要一定的时间,这段时间内系统又又一次定位了一次或则多次,所以应该停止定位之后再输出,这样就能够仅仅是输出当前的一次更新信息。
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
[self.locationManager stopUpdatingLocation];//先停止定位
CLLocation *location = [locations lastObject];
NSLog(@" location is :%@ ",location.description);
}
问题2、用模拟器定位失败
2015-08-14 17:17:17.455 mylocation[2953:98656] Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
//定位失败之后显示的信息。
解决方法:
1.确定模拟器(手机)已经联网而且同意程序获取地理位置
2.重置地理位置服务或者网络服务
PS:假设是模拟器就果断直接重置模拟器吧 IOS Simulator - Reset Content and Settings..。
这样就又一次设置模拟器。模拟器就是初始化的状态。
//方向的更新
- (void)locationManager:(CLLocationManager *)manager
didUpdateHeading:(CLHeading *)newHeading;
//用于推断是否显示方向的校对,返回yes的时候,将会校对正确之后才会停止,或者dismissheadingcalibrationdisplay方法解除。
- (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager;
- (void)locationManager:(CLLocationManager *)manager
didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region;
- (void)locationManager:(CLLocationManager *)manager
didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region;
- (void)locationManager:(CLLocationManager *)manager
rangingBeaconsDidFailForRegion:(CLBeaconRegion *)region
withError:(NSError *)error ;
//进入指定区域
- (void)locationManager:(CLLocationManager *)manager
didEnterRegion:(CLRegion *)region ;
//离开指定的区域
- (void)locationManager:(CLLocationManager *)manager
didExitRegion:(CLRegion *)region;
//定位失败
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error;
//区域定位失败
- (void)locationManager:(CLLocationManager *)manager
monitoringDidFailForRegion:(CLRegion *)region
withError:(NSError *)error ;
//改变里授权的状态
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status ;
//開始控制指定的区域
- (void)locationManager:(CLLocationManager *)manager
didStartMonitoringForRegion:(CLRegion *)region;
//已经停止位置的更更新
- (void)locationManagerDidPauseLocationUpdates:(CLLocationManager *)manager ;
//位置定位又一次開始定位位置的更新
- (void)locationManagerDidResumeLocationUpdates:(CLLocationManager *)manager ;
//已经完毕了推迟的更新
- (void)locationManager:(CLLocationManager *)manager
didFinishDeferredUpdatesWithError:(NSError *)error;
//就是已经訪问过的位置,就会调用这个表示已经訪问过。这个在栅栏或者定位区域都是使用到的
- (void)locationManager:(CLLocationManager *)manager didVisit:(CLVisit *)visit;
@end
写的时候easy遗漏的就是设置代理:
Assigning to 'id<CLLocationManagerDelegate>' from incompatible type 'ViewController *const __strong'
出现这个错误:
是由于有的时候还没有继承对应的代理。
easy错误的地方:
- 一些差别:能够通过配置NSLocationAlwaysUsageDescription或者NSLocationWhenInUseUsageDescription来告诉用户使用定位服务的目的。这个设置的信息是在用户第一次打开应用的app的时候,会弹出的信息显示
- 可是不同的是这个配置是必须的,假设不进行配置则默认情况下应用无法使用定位服务。打开应用不会给出打开定位服务的提示,也无法获取到位置信息,除非安装后自己设置此应用的定位服务。同一时候,在应用程序中须要依据配置对requestAlwaysAuthorization或requestWhenInUseAuthorization方法进行请求。
</p><p>开发人员能够在info.plist 文件里设置NSLocationUsageDescription 说明定位identifier目的
- [Privacy -Location Usage Description] 这个在ios8能够不写
- //这是用户的描写叙述,在ios8之前写的。
CLLocationManagerDelegate的解说的更多相关文章
- 框架设计之ADO.NET Command的ExecuteScalar误用情景及底层解说
最近下载了点资料,学了学Android,发现Android入门还算简单,从.NET过渡到Android,也就三七十一天的事. 大伙有空也可以学学... 好了,言归正文,那日,有网友发了一个他们公司的数 ...
- 【开源】OSharp框架解说系列(1):总体设计及系列导航
系列文章导航 [开源]OSharp框架解说系列(1):总体设计 [开源]OSharp框架解说系列(2.1):EasyUI的后台界面搭建及极致重构 [开源]OSharp框架解说系列(2.2):EasyU ...
- 【开源】OSharp3.3框架解说系列:开发计划与进度
OSharp是什么? OSharp是个快速开发框架,但不是一个大而全的包罗万象的框架,严格的说,OSharp中什么都没有实现.与其他大而全的框架最大的不同点,就是OSharp只做抽象封装,不做实现.依 ...
- 【开源】OSharp3.3框架解说系列(7.1):初始化流程概述
OSharp是什么? OSharp是个快速开发框架,但不是一个大而全的包罗万象的框架,严格的说,OSharp中什么都没有实现.与其他大而全的框架最大的不同点,就是OSharp只做抽象封装,不做实现.依 ...
- 【开源】OSharp3.3框架解说系列:重新开源及3.3版本新特性
OSharp是什么? OSharp是个快速开发框架,但不是一个大而全的包罗万象的框架,严格的说,OSharp中什么都没有实现.与其他大而全的框架最大的不同点,就是OSharp只做抽象封装,不做实现.依 ...
- 【开源】OSharp3.0框架解说系列(6.2):操作日志与数据日志
OSharp是什么? OSharp是个快速开发框架,但不是一个大而全的包罗万象的框架,严格的说,OSharp中什么都没有实现.与其他大而全的框架最大的不同点,就是OSharp只做抽象封装,不做实现.依 ...
- 【开源】OSharp3.0框架解说系列:新版本说明及新功能规划预览
OSharp是什么? OSharp是个快速开发框架,但不是一个大而全的包罗万象的框架,严格的说,OSharp中什么都没有实现.与其他大而全的框架最大的不同点,就是OSharp只做抽象封装,不做实现.依 ...
- 【开源】OSharp框架解说系列(6.1):日志系统设计
OSharp是什么? OSharp是个快速开发框架,但不是一个大而全的包罗万象的框架,严格的说,OSharp中什么都没有实现.与其他大而全的框架最大的不同点,就是OSharp只做抽象封装,不做实现.依 ...
- 【开源】OSharp框架解说系列(5.2):EntityFramework数据层实现
OSharp是什么? OSharp是个快速开发框架,但不是一个大而全的包罗万象的框架,严格的说,OSharp中什么都没有实现.与其他大而全的框架最大的不同点,就是OSharp只做抽象封装,不做实现.依 ...
随机推荐
- C#:使用FastReport打印带图片传参模板的实现方法
大家都知道,C#打印图片可以直接调用PrintDocument控件的PrintPage事件,通过画刷对image对象直接进行绘制.但是这种方法存在局限,例如如果打印的图片需要按纸张大小进行缩放的话,那 ...
- Nginx作为负载均衡服务
负载均衡服务器配置: 注意:upstream和server同级 案例: 建立两个基于端口的虚拟主机来模拟两台web服务器. (1)新建一个www.123.com:81和www.123.com:82的虚 ...
- 基于mybatis向oracle中插入数据的性能对比
数据库表结构: 逐条插入sql语句: <insert id="insert" parameterType="com.Structure"> INSE ...
- (转)vuex2.0 基本使用(1) --- state
Vuex 的核心是 store, 它是一个通过 Vuex.Store 构造函数生成的对象.为什么它会是核心呢?因为我们调用这个构造函数创建store 对象的时候,给它传递参数中包装了state, mu ...
- ViewPager PagerAdapter 的使用
1: 目的,实现全屏滑动的效果 2:类似于BaseAdapter public class MyPagerAdapter extends PagerAdapter { private Context ...
- Azure Service Bus
Azure Service Bus 是类似Rabbit的一个队列的应用. 找了两个基本的教程 First(但是这个,没有写怎么去链接账户) Sec:这个有 Third(讲的也很好) Windo ...
- jQuery的基本概念与高级编程
年创建的一个年月面世的1.5.2版本.作为一个JavaScript库,jQuery极大程度上解决了浏览器的兼容性问题,能够在IE 6.0 +.FF 2.0 +.Safari 3.0 +.Opera 9 ...
- 【sqli-labs】 less20 POST - Cookie injections - Uagent field - Error based (POST型基于错误的cookie头部注入)
以admin admin成功登陆之后,保存并显示了cookies信息 如果不点击Delete Your Cookie!按钮,那么访问 http://localhost/sqli-labs-master ...
- logger日志
Level 描述 ALL 各级包括自定义级别 DEBUG 指定细粒度信息事件是最有用的应用程序调试 ERROR 错误事件可能仍然允许应用程序继续运行 FATAL 指定非常严重的错误事件,这可能导致应用 ...
- null值处理
一,在实体类的上面加注解 import com.fasterxml.jackson.annotation.JsonInclude @JsonInclude(JsonInclude.Include.NO ...