views:

371

answers:

2

I'm using following conditions in-order to make sure that the location i get has adequate accuracy, In my case kCLLocationAccuracyBest. But the problem is that i still get inaccurate location.

// Filter out nil locations
if(!newLocation)
    return;

// Make sure that the location returned has the desired accuracy
if(newLocation.horizontalAccuracy < manager.desiredAccuracy)
    return;

// Filter out points that are out of order    
if([newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp] < 0)
    return;

// Filter out points created before the manager was initialized
NSTimeInterval secondsSinceManagerStarted = [newLocation.timestamp timeIntervalSinceDate:locationManagerStartDate];
if(secondsSinceManagerStarted < 0)
    return;

// Also, make sure that the cached location was not returned by the CLLocationManager (it's current) - Check for 5 seconds difference
if([newLocation.timestamp timeIntervalSinceReferenceDate] < [[NSDate date] timeIntervalSinceReferenceDate] - 5)
    return;

When i activate the GPS, i get inaccurate results before i actually get an accurate result. What methods do you use to get accurate/precise location information?

A: 

GPS is slow, at least compared to user patience, so the location manager returns the best it has until it gets a new, valid GPS read. You can either make the user wait however long it takes to get an accurate read, or have some kind of incremental feedback the way google maps does, with a circle than a dot.

drawnonward
Actually i am showing the blue dot and the circle, but the problem is that i'm also recording the location changes, so the first few locations are almost always inaccurate. How can i make sure that the location that i've received now is the most accurate! I think i've placed all the necessary conditions in my code, but the inaccurate locations still bypass my code.
Mustafa
newLocation.horizontalAccuracy can be negative. And you could check it against an actual number of meters instead of the AccuracyBest constant.
drawnonward
Ah, thanks for the tip. Since AccuracyBest has a -ve value it's not advisable to use it for comparison with horizontalAccuracy. I guess I'll also have to add some timer or a scheduler to use the last known location... if I'm not getting the desired location accuracy, or location manager has stopped sending location update message because user has stopped? I've looked all over to see if anyone has shared this logic but no one has. I wonder if there is a better way to handle this.
Mustafa
A: 

The main reason i was getting inaccurate results was because of this condition:

if(newLocation.horizontalAccuracy < manager.desiredAccuracy)

I was using kCLLocationAccuracyBest as desiredAccuracy and it's a negative number. You shouldn't use it for comparison.

Solution: if(newLocation.horizontalAccuracy < 10.0)

Mustafa