ios - 无法获取更新的坐标以将它们附加到 SWIFT 4 中的数组
问题描述
我正在尝试存储actualRouteInUseAnnotation: [MKAnnotation]
路线的开始和结束位置,以及路线的actualRouteInUseCoordinates : [CLLocationCoordinate2D]
所有坐标。注释数组得到它的值,但坐标数组没有。
使用的功能是:开始:
func startTracking2() {
self.trackingIsActive = true
locationManager.stopUpdatingLocation()
let startRoutePosition = RouteAnnotation(title: "Route Start", coordinate: (locationManager.location?.coordinate)!, imageName: "Route Start")
self.actualRouteInUseAnnotations.append(startRoutePosition)
// self.actualRouteInUseCoordinates.append((locationManager.location?.coordinate)!)
print(actualRouteInUseCoordinates)
print(actualRouteInUseAnnotations)
}
对于停止:
func stopTracking2() {
self.trackingIsActive = false
locationManager.stopUpdatingLocation()
let stopRoutePosition = RouteAnnotation(title: "Route Stop", coordinate: (locationManager.location?.coordinate)!, imageName: "Route Stop")
self.actualRouteInUseAnnotations.append(stopRoutePosition)
print(actualRouteInUseCoordinates)
print(actualRouteInUseAnnotations)
}
对于更新的坐标:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let mostRecentLocation = locations.last else { return }
// setCoordinates() // set actual user coordinates
// storeUserLocation() // store auctual user coordinates
self.actualRouteInUseCoordinates.append(mostRecentLocation.coordinate)
}
你能明白为什么我没有将更新的坐标附加到数组中吗?
解决方案
推荐阅读
- c# - 相机旋转 SolvePnp
- kubernetes - 如何处理特使中的临时端口耗尽
- ios - 旋转 UIBezierPath 矩形
- javascript - 如何根据表格元素及其ID设置模态对话框的标题文本
- r - 在 Rgraphviz 中设置子图/集群属性
- c++ - C ++数组交换并找到最小元素
- keras - Keras 的一类分类
- sql-server - SQL Server 复制数据类型从 tinyint 更改为 int
- javascript - Angular / rxJS:combineLatest - 如何处理 404 错误
- python - 使用 pipenv 和 setup.py 安装私有仓库失败