i used CLLoction manager to get location.b开发者_运维问答ut when ever i start my location then it gives me oldlocation which is store in device previously.i want to reset the location for this i used flag on first launch of application i used newlocation and call stopupdateinglocation and startupdatinglocation method.But oldlocation is not changed it show old location.
Every CLLocation
has a timestamp
property that you can use to filter all location updates that are too old for your usage.
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSTimeInterval age = [newLocation.timestamp timeIntervalSinceNow];
if(age < SOME_CONSTANT_IN_SECONDS)
{
//Use location
}
}
You can't clear the old location, but you can check the horizontalAccuracy to know if this is a good location (current) or something old and irrelevant.
精彩评论