gpt4 book ai didi

ios - clocationmanager 在前几秒内返回零纬度和经度。我怎么能够

转载 作者:行者123 更新时间:2023-11-28 15:41:31 26 4
gpt4 key购买 nike

我的应用程序有一个 TableView ,加载速度比 clocationmanager 实例初始化快(至少这是我的怀疑),并且在运行时的前几秒,clocation 返回经度和纬度都为零。我应该怎么做才能避免这个问题?

最佳答案

好的,首先加载一个空表,然后在 locationManager 委托(delegate)中进行位置验证检查,一旦位置有效,重新加载 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

}

}

关于ios - clocationmanager 在前几秒内返回零纬度和经度。我怎么能够,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43641572/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com