How to remove cache of cllocation?
Asked Answered
E

1

6

I am developing an iPhone app which is a location aware app . Currentlly the app is working fine except the caching of previous location . The first time I start the application location manager fetches the current location and then I display nearby things based on the current location .

But from the next it uses previously fetched location and until I restart the phone it will fetch the same location . So up to this point I am clear that the location manager caches the location .

So my question is how to remove this cache and force the location manager to fetch a new location thanks

Ethelda answered 1/2, 2010 at 10:58 Comment(0)
A
9

Actually I don't think you can : it's up to you (in your CLLocationManagerDelegate instance) to filter the position you receive based on its timestamp (to ensure that the position you work on is a recent one, not a cached one).



-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ NSDate *eventDate = newLocation.timestamp; NSTimeInterval howRecent = [eventDate timeIntervalSinceNow]; //Is the event recent and accurate enough ? if (abs(howRecent) < SECS_OLD_MAX) { //WORK WITH IT ! } .... ....

Arborvitae answered 1/2, 2010 at 11:2 Comment(6)
I am just asking you for suggetion that what should be set in SEC_OLD_MAX ?Ethelda
Also what to do if the interval is greater then secs old max ?Ethelda
Usually the time difference to a current location is well below a second. If the time difference to now is greater than a second it is probably a cached location.White
Thanks felix. One last thing if I get the caches one how to ignore it and get a new one should I sto and start the location manager again ?Ethelda
Just do nothing if the location is not recent enough and wait for the next one. You'll keep on getting new positions as long as you don't invoke the stopUpdatingLocation on the CLLocationManager (or if you delegate receive a "failed" event).Arborvitae
This solution not worked when user change their device's date and time.Fascista

© 2022 - 2024 — McMap. All rights reserved.