ios - 如何在 10 毫秒的时间间隔内将纬度和经度附加到字典数组中?

标签 ios swift

我正在制作一个应用程序,我必须每隔 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/

相关文章:

ios - 将 GIF 复制到 UIPasteboard

ios - lldb 中的 Swift 泛型 - 错误 : unable to find any types that match the raw type for full type

ios - CAGradientLayer 没有跨越我按钮的整个宽度 - xcode

ios - [__NSCFString objectForKey :]: crash on textfield search

ios - 任何手指扫描示例教程iPhone SDK

ios - stringForKey 导致应用程序崩溃

ios - 如何在 iOS 8 中为以前接受过通知的用户启用推送通知?

ios - Azure SQL数据库新创建的表不允许插入数据,但所有旧表都允许插入数据

ios - 将滤镜应用于实时相机预览 - Swift

arrays - 根据前一个元素的每个值的百分比差异创建一个数组