locationManager:didUpdateLocations:始终被调用多次 [英] locationManager:didUpdateLocations: always be called several times
问题描述
当视图确实出现时,我开始更新当前位置,并在调用 locationManager:didUpdateLocations:
时停止更新位置。但是为什么总是多次调用 locationManager:didUpdateLocations:
?我错过了什么?
I start updating current location when the view did appear, and stop updating location whenever locationManager:didUpdateLocations:
is called. But why the locationManager:didUpdateLocations:
always be called several times? What have I missed?
#import "ViewController.h"
@interface ViewController (){
CLLocationManager *locationManager; // location manager for current location
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self startUpdatingCurrentLocation];
}
- (void)startUpdatingCurrentLocation
{
if (!locationManager)
{
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
locationManager.distanceFilter = 10.0f; // we don't need to be any more accurate than 10m
}
[locationManager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
[locationManager stopUpdatingLocation];
}
@end
推荐答案
可能取决于您为locationManager设置的精度。您有3种本地化Cell Radio,WiFi Map,GPS。如果将精度设置为最佳,则位置管理器将继续检查您的位置,如果精度更高的位置不在距离过滤器的范围内,则将再次调用委托方法。
Probably it depends about the accuracy you set to the locationManager. You have 3 kinds o localization Cell Radio, WiFi Map, GPS. If you set best as accuracy the location manager will continue to check you position, if the location with better accuracy is out of the range of the distance filter the delegate method will be called again.
这篇关于locationManager:didUpdateLocations:始终被调用多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!