我使用此设置设置位置精度:
locationManager.desiredAccuracy = kCLLocationAccuracyBest
我得到了这个位置:
if let location = locations.first {
....
}
但它多次更新位置,其中许多都不准确。例如,当我找到位置时,距离设备位置约100米。
我如何获得准确的位置?
我知道,在设备获得该位置的修复之前,前几个位置不准确。
接收器尽力达到要求的准确度;但是,实际的准确性并不能保证。
因此,您无法保证检测到的位置有多近,但您可以尝试其他一些事项:
kCLLocationAccuracyBestForNavigation
。这应该可以让您获得更准确的读数,但需要更多的电池使用成本。多年来的经验与核心位置。 GPS芯片需要一段时间才能“预热”,有时会在锁定之前报告几个位置。您将在室内体验这一点,而不是清晰地看到天空。带有金属屋顶的建筑物也会影响精度。但是,如果使用distanceFilter属性(以米为单位)distanceFilter并使用此属性horizontalAccuracy设置所需的精度,则可以忽略gps更新(如果它们在某个阈值之内/之外)。
您可以检查每次更新的准确性,并过滤位置,直到获得可靠的准确度:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print(manager.location!.horizontalAccuracy)
if locations.last!.horizontalAccuracy <= manager.desiredAccuracy{
print(manager.location)
}
}
看一下该位置的horizontalAccuracy属性(CLLocation)。这以米为单位。您可以使用此属性忽略不够准确的位置读数。