【问题标题】:How to make location more accurate in iOS?如何在 iOS 中使定位更准确?
【发布时间】:2015-08-20 20:21:54
【问题描述】:

我正在构建一个基于位置的应用程序。有没有办法让我通过 CLLocationManager 获得的位置更准确?

我需要确保精度在 50 米以内。

到目前为止,这是我的代码:

func startSignificantChangeUpdates(){
    if (locationManager.respondsToSelector(Selector("requestWhenInUseAuthorization"))) {
        locationManager.requestWhenInUseAuthorization()
    }else {
        locationManager.startUpdatingLocation()
    }

    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
    location = locationManager.location
}

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
    if let newLocation = locations.last as? CLLocation {
        //Lets not bother if the location is less than 500 meters
        let oldLocation = location
        location = newLocation
        var distance = oldLocation?.distanceFromLocation(newLocation)
        if distance > 500 {

            NSNotificationCenter.defaultCenter().postNotificationName("location", object: self)
        }
        if distance > 50 {
            NSNotificationCenter.defaultCenter().postNotificationName("imatlocation", object: self)
        }
    }

}

【问题讨论】:

  • 尽管您要求的准确性很高,但您可能得不到。有时该位置距离很远,即使在要求最佳精度时也可能相距一英里。因此,请确保您获得的准确度 而不是您所要求的准确度 。仅仅因为您要求特定的准确性并不意味着您得到了它。

标签: ios swift geolocation cllocationmanager


【解决方案1】:

为了返回位置的准确性,您需要检查该位置的horizontalAccuracy,这将为您提供该位置的不确定性半径(以米为单位),然后您可以根据如何决定采取行动或拒绝该位置没错。

【讨论】:

    【解决方案2】:

    您可以更改您想要使用的准确度

    kCLLocationAccuracyBest
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-20
      • 2013-09-09
      • 1970-01-01
      • 2018-03-06
      • 2014-11-05
      • 1970-01-01
      相关资源
      最近更新 更多