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

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

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

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

     




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值