use*_*284 1 iphone cllocationmanager
我使用CLLoction管理器来获取location.but什么时候我开始我的位置然后它给我oldlocation先前存储在设备中.我想在首次启动应用程序时重置此i used flag的位置我使用newlocation并调用stopupdateinglocation和startupdatinglocation方法.但是oldlocation没有改变它显示旧位置.
每个CLLocation都有一个timestamp属性,您可以用来过滤所有过于陈旧的位置更新.
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSTimeInterval age = [newLocation.timestamp timeIntervalSinceNow];
if(age < SOME_CONSTANT_IN_SECONDS)
{
//Use location
}
}
Run Code Online (Sandbox Code Playgroud)