我正在使用CLLocationManger更新当前位置。尽管它给我的位置,但我所得到的位置是更老的时间戳。我面临的问题是,如何强制locationcontroller更新新的位置而不是缓存的位置。CLLocationManger给出了旧的位置。如何获得新的位置?
目前我使用本教程......
http://www.mobileorchard.com/hello-there-a-corelocation-tutorial/
有人知道如何在当前的时间戳没有缓存的一个更新的位置?
我正在使用CLLocationManger更新当前位置。尽管它给我的位置,但我所得到的位置是更老的时间戳。我面临的问题是,如何强制locationcontroller更新新的位置而不是缓存的位置。CLLocationManger给出了旧的位置。如何获得新的位置?
目前我使用本教程......
http://www.mobileorchard.com/hello-there-a-corelocation-tutorial/
有人知道如何在当前的时间戳没有缓存的一个更新的位置?
你是在模拟器上还是在iPhone上运行你的项目?如果您正在模拟器上运行项目,则
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
将只被调用一次。
如果您正在设备上进行测试,则应在每次更改您的位置时调用它。
确保您已设置的位置管理器属性,
locationManager.delegate=self;
[locationManager startUpdatingLocation];
希望帮助...
您可以使用进行选择使用此方法
- (IBAction)update {
locmanager = [[CLLocationManager alloc] init];
[locmanager setDelegate:self];
[locmanager setDesiredAccuracy:kCLLocationAccuracyBest];
NSLog(@"*********this is location update method of login view controller");
[locmanager startUpdatingLocation];
}
-(void)awakeFromNib {
[self update];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
if (wasFound) return;
wasFound = YES;
CLLocationCoordinate2D loc = [newLocation coordinate];
lat2 = [[NSString stringWithFormat: @"%f", loc.latitude]retain];
logg2= [[NSString stringWithFormat: @"%f", loc.longitude]retain];
NSLog(@"latitude is %@",lat2);
NSLog(@"longitude is %@",logg2);
}
调用Update方法在viewdidload方法中。这里lat2和logg2是字符串值。 如果问题无法解决,然后键入如何找到google.you目前的位置将得到很多的例子与解释的源代码
你可以做的最好的是扔掉太旧的地点,无论你决定的任何标准为您的应用程序设置。重新启动位置管理器应该告诉系统你想要一个新的位置,但是通常你找回的第一个位置可能是上一次的位置。检查时间戳可能是你所能做的,但要准备好可能永远不会得到更新的位置。根据我的经验,我发现如果设备没有移动,如果它检测到当前位置足够好,就不会用新位置更新系统。