gpt4 book ai didi

iphone - 位置管理器 :didUpdateLocations: always be called several times

转载 作者:可可西里 更新时间:2023-11-01 03:42:01 24 4
gpt4 key购买 nike

我在 View 确实出现时开始更新当前位置,并在调用 locationManager:didUpdateLocations: 时停止更新位置。但为什么 locationManager:didUpdateLocations: 总是被调用多次?我错过了什么?

#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 种 o 本地化手机 radio 、WiFi map 、GPS。如果您将精度设置为最佳,位置管理器将继续检查您的位置,如果精度更高的位置超出距离过滤器的范围,将再次调用委托(delegate)方法。

关于iphone - 位置管理器 :didUpdateLocations: always be called several times,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16077008/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com