문제

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?

도움이 되었습니까?

해결책 2

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)

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top