gpt4 book ai didi

iphone - CLLocationManager 正在提供旧位置

转载 作者:行者123 更新时间:2023-12-03 20:28:37 25 4
gpt4 key购买 nike

在我的标题中放置

CLLocationManager *locationManager;
@property (nonatomic, retain) CLLocationManager *locationManager;

在我的实现文件中:

- (void)viewDidLoad
{
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.distanceFilter = 50.0f;
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
self.locationManager.delegate = self;
[locationManager startUpdatingLocation];
[super viewDidLoad];
}

然后在委托(delegate)方法中

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"Location: %g,%g", newLocation.coordinate.latitude, newLocation.coordinate.longitude );

}

现在我不断获得旧的纬度和经度值

用谷歌搜索找不到解决方案,我不明白我做错了什么,

请帮忙

最佳答案

您可以使用timestamp过滤太旧的位置更新的位置:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if ([newLocation.timestamp timeIntervalSinceNow] < -60) return; // location is not fresh
...
}

关于iphone - CLLocationManager 正在提供旧位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6244649/

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