我正在制作一个应用程序,我必须每隔 10 毫秒发送一次字典的纬度和经度数组。我是这样做的。
func locationManager(_ manager: CLLocationManager,
didUpdateLocations locations: [CLLocation]) {
myLocation = locations.last
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
currentSpeed = (manager.location?.speed)! as Double
lat = locValue.latitude as Double
lng = locValue.longitude as Double
var arrayDict = [[String : AnyObject]]
arrayDict.append["lat":lat , "long" : long]
}
但是这里我有所有的纬度和经度,我只想在 10 毫秒的时间间隔内附加元素。 提前致谢。
最佳答案
取一个全局命名为“locationBool”的 bool 值
var locationBool = Bool()
var arrayDict = [[String : AnyObject]]
override func viewDidLoad()
{
super.viewDidLoad()
var timer = Timer.scheduledTimer(timeInterval: 0.10, target: self, selector: #selector(self.update), userInfo: nil, repeats: true);
}
func update() {
// Something code
locationBool = false
}
func locationManager(_ manager: CLLocationManager,
didUpdateLocations locations: [CLLocation])
{
if locationBool == false
{
locationBool = true
myLocation = locations.last
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
currentSpeed = (manager.location?.speed)! as Double
lat = locValue.latitude as Double
lng = locValue.longitude as Double
arrayDict.append["lat":lat , "long" : long]
}
}
关于ios - 如何在 10 毫秒的时间间隔内将纬度和经度附加到字典数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42481197/