views:

80

answers:

2

Hi frnz ,

How to remove cached data which is sent by CLLocationManager and how to increase its accuracy.Every time i launch the app it gives me cached data and updates it after some time.I have seen several threads but i am not able to get a concrete sol .can anybody provide me the code? I am using the following method to get position data....

- (void)locationManager:(CLLocationManager *)manager
     didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation

I have set the delegate and accuracy here.....

- (void)viewDidLoad {
[super viewDidLoad];
bestEffortAtLocation = nil;
latLocationArray = [[NSMutableArray alloc]init]; 
longLocationArray = [[NSMutableArray alloc]init];
locationManager =[[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.distanceFilter =  kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];

}

Also can i use CLLocationManager to compute the distance travelled by person?

+1  A: 

There doesn't seem to be a way to dump the cached data. The docs recommend using the timestamp property of the CLLocation object to determine how recent the data is, which is what I do.

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
    //wait until we get a recent location, no more than 2 minutes old
    if([newLocation.timestamp timeIntervalSinceNow] <= (60 * 2)){
        DLog(@"New location:\n\tLat: %f\n\tLon: %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude)
        //turn off location updates
        [self.locManager stopUpdatingLocation];
        DLog(@"Stopping Location Updates");
        //Do stuff
    }
}

In my testing I haven't had to wait more than a second or two before I get new data.

On your second point, you could have a variable that you add to whenever you get a location update. The distance between updates can be pretty easy to get using CLLocation's distanceFromLocation: method.

paxswill
thx paxswill....but i am still getting cached values
Siddharth
A: 

Instead of set the distanceFilter to kCLDistanceFilterNone

i.e. locationManager.distanceFilter = kCLDistanceFilterNone;

You may give some value to distanceFilter and check

For e.g. locationManager.distanceFilter =0.5f;

And to calculate distance travel you have to implement the didUpdateToLocation: fromLocation:

where you have to find the new latitude and longitude

Finally CLLocationObject = newLocation;

CLLocationDistance yourdistance = [newLocation getDistanceFrom:CLLocationObject];

NSString *distance = [[NSString alloc] initWithFormat:@"%gm", yourdistance ];

NSLog(@"you have travel=%@",distance);

raaz
i have used the value of distanceFilter = 1.0 still it is updating the location when iPhone is still.
Siddharth
Do you test it in iPhone device over wifi or through any carrier
raaz
hi razz............actually i have tested the application in iPad (device).....!
Siddharth