cllocationmanager在前几秒返回零纬度和经度。我怎么能够

时间:2017-04-26 18:09:47

标签: ios swift xcode cllocation

我的应用程序有一个表视图,其加载速度比cllocationmanager实例初始化(至少这是我的怀疑),并且在运行时cllocation的前几秒内返回零的纬度和纬度。我该怎么做才能避免这个问题?

1 个答案:

答案 0 :(得分:1)

好的,首先加载一个空表,然后在locationManager委托中放置位置验证检查,一旦该位置有效,重新加载tableview。这是一个简单的例子:

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    let newLocation = locations.last

    let timeDiff = newLocation?.timestamp.timeIntervalSinceNow

    if timeDiff < 5 && (newLocation?.horizontalAccuracy)!<=self.accuracyNeeded{



        //stop updating location & heading
        self.locationManager?.stopUpdatingLocation()

        //set currentUserLocation
        Model.sharedInstance.currentUserLocation=newLocation?.coordinate

        //Update tableview here            

        //remove delegate
        self.locationManager?.delegate = nil

    }

}