开发者

iPhone Development - Location Accuracy

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?


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.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜