首页 > 其他 > 详细

locationManager 定位地址不准,获取回调更准的方法

时间:2015-07-21 17:18:58      阅读:404      评论:0      收藏:0      [点我收藏+]

原来的写法,这种写法获取第一次返回的结果,然后就会停止更新经纬度

- (void)operationLocations:(NSArray *)locations{
    [self.locationManager stopUpdatingLocation];
     ....
     ....
}

- (void)locationManager:(CLLocationManager *)manager
     didUpdateLocations:(NSArray *)locations
   [self operationLocations:locations];
}



猜想:LocationManager  定位回调会多次回调,及多次纠偏。所以,如果是最后一次,则是最准确的。

了解到:

  // 延迟0.2s执行,如果有新任务,则取消原先的任务。最终只执行最后一次任务。

    [[self classcancelPreviousPerformRequestsWithTarget:self selector:@selector(todoSomething:object:sender];

    [self performSelector:@selector(todoSomething:withObject:sender afterDelay:0.2f];


于是新写法如下:

- (void)operationLocations:(NSArray *)locations{
    [self.locationManager stopUpdatingLocation];
     ....
     ....
}

- (void)locationManager:(CLLocationManager *)manager
     didUpdateLocations:(NSArray *)locations{
   
  [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(operationLocations:) object:locations];
    [self performSelector:@selector(operationLocations:) withObject:locations afterDelay:0.2f];

}



版权声明:本文为博主原创文章,未经博主允许不得转载。

locationManager 定位地址不准,获取回调更准的方法

原文:http://blog.csdn.net/lihongli528628/article/details/46986073

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!