CLLocationManager提供了旧位置 [英] CLLocationManager is giving old location

查看:56
本文介绍了CLLocationManager提供了旧位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我放在标题中

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];
}

然后使用委托方法

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

}

现在我一直在获取经度和纬度的旧值

now I keep getting an old value for latitude and longitude

用Google搜索解决方案,我找不到任何解决方案,我不明白自己在做错什么,

googled for a solution i could not find any, i don't understand what i am doing wrong,

请帮助

推荐答案

您可以使用

You can use the timestamp of the location to filter location updates that are too old:

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

这篇关于CLLocationManager提供了旧位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆