CLLocationManagerDelegate定位的讲解

1、//新的方法,登陆成功之后(旧的方法就不管了)
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray

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;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值