clocationmanager returns 前几秒的纬度和经度为零。我怎么能够
cllocationmanager returns latitude and longitude of zero in the first couple of seconds. How can I
我的应用程序有一个 table 加载速度比 clocationmanager 实例初始化更快的视图(至少这是我的怀疑),并且在运行时 clocation 的前几秒 returns 纬度和纬度为零。我应该怎么做才能避免这个问题?
好的,首先加载一个空的 table 然后在 locationManager 委托中进行位置验证检查,一旦位置有效,重新加载 table 视图。这是一个简单的例子:
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
}
}
我的应用程序有一个 table 加载速度比 clocationmanager 实例初始化更快的视图(至少这是我的怀疑),并且在运行时 clocation 的前几秒 returns 纬度和纬度为零。我应该怎么做才能避免这个问题?
好的,首先加载一个空的 table 然后在 locationManager 委托中进行位置验证检查,一旦位置有效,重新加载 table 视图。这是一个简单的例子:
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
}
}