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错误的地方:

  1. 一些差别:能够通过配置NSLocationAlwaysUsageDescription或者NSLocationWhenInUseUsageDescription来告诉用户使用定位服务的目的。这个设置的信息是在用户第一次打开应用的app的时候,会弹出的信息显示
  2. 可是不同的是这个配置是必须的,假设不进行配置则默认情况下应用无法使用定位服务。打开应用不会给出打开定位服务的提示,也无法获取到位置信息,除非安装后自己设置此应用的定位服务。同一时候,在应用程序中须要依据配置对requestAlwaysAuthorization或requestWhenInUseAuthorization方法进行请求。

    </p><p>开发人员能够在info.plist 文件里设置NSLocationUsageDescription 说明定位identifier目的

  3. [Privacy -Location Usage Description]  这个在ios8能够不写
  4. //这是用户的描写叙述,在ios8之前写的。

最新文章

  1. iOS--碎片知识锦集
  2. ThinkPHP框架下的表单验证
  3. dede文章调用时过滤调 body里面的style属性和值
  4. debian/ubuntu 下ISE安装
  5. 【C-01关键字】
  6. JS小游戏-蓝色拼图
  7. Java 基本数据类型长度
  8. pip安装模块警告InsecurePlatformWarning: A true SSLContext object is not available.
  9. c++ 设计模式1
  10. 杭电ACM2091--空心三角形
  11. 小记 js unicode 编码解析
  12. jquery datatable 参数api
  13. 百度的js日历
  14. NodeJS之异常处理
  15. android开发_view和view属性
  16. Keepalive配置说明
  17. linux下的dhcp服务器实现
  18. Python全栈开发之路 【第十八篇】:Ajax技术
  19. keepalived + nginx 搭建负载均衡集群
  20. ZYNQ学习之路1. Linux最小系统构建

热门文章

  1. Elasticserach 同步索引报错:ElasticSearch ClusterBlockException[blocked by: [FORBIDDEN/12/index read-only / allow delete (api)]
  2. C# 设置百分比保留2位数
  3. HTML5 postMessage 和 localStorage 实现窗口间通信
  4. 【Oracle】DBMS_STATS.GATHER_TABLE_STATS
  5. 释放Win8.1 WinSxS冗余更新,微软Dism来解决
  6. 安卓手机USB无法共享、上网或卡顿的解决方法
  7. jQuery插件的怎么写
  8. 备份-泛函编程(23)-泛函数据类型-Monad
  9. python核心编程中的对象值比较VS对象身份比较(转载)
  10. 微信小程序例子-保存图片到手机相册