iPhone开发 - 位置准确性

时间:2010-04-16 05:28:50

标签: iphone mkmapview cllocationmanager userlocation

我正在使用以下条件以确保我获得的位置具有足够的准确性,在我的情况下为kCLLocationAccuracyBest。但问题是我仍然得到不准确的位置。

// 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;

当我激活GPS时,在获得准确结果之前,我得到的结果不准确。您使用什么方法来获取准确/精确的位置信息?

2 个答案:

答案 0 :(得分:0)

GPS速度很慢,至少与用户耐心相比,所以位置管理器会返回最佳状态,直到获得新的有效GPS读取。您可以让用户等待获得准确读取所需的时间,或者像谷歌地图那样获得某种增量反馈,使用圆圈而不是点。

答案 1 :(得分:0)

我获得不准确结果的主要原因是因为这种情况:

if(newLocation.horizontalAccuracy < manager.desiredAccuracy)

我正在使用kCLLocationAccuracyBest作为所需的准确度,这是一个负数。你不应该用它来进行比较。

解决方案: if(newLocation.horizontalAccuracy < 10.0)