【发布时间】:2019-07-23 14:14:58
【问题描述】:
无法将“[字典]”类型的值转换为预期值 参数类型“UnsafePointer”
是我在尝试将坐标插入数组时遇到的错误吗?
这是我的代码:
var locations: [CLLocationCoordinate2D] = []
//Updating location + polylines
@objc func update()
{
Annotationtimer = Timer.scheduledTimer(withTimeInterval: 10, repeats: true, block: { (timerr) in
let currentLat = self.locationManager.location?.coordinate.latitude
let currentLong = self.locationManager.location?.coordinate.longitude
let location = [(currentLat!), (currentLong!)]
self.locations.append(location) //HERE IS THE ERROR
print(self.locations)
//Draw polyline on the map
let aPolyLine = MKPolyline(coordinates: locations, count: locations.count)
//Adding polyline to mapview
self.mapView.addOverlay(aPolyLine)
})
}
我正在尝试将当前位置插入一个数组,当我按下一个按钮时,我想从头开始绘制折线,通过所有坐标。
我做错了什么?如何正确插入坐标?我已经阅读了有关此的其他线程,但它们都没有真正起作用。所以我想创建一个新的。
为什么不喜欢?至少你可以告诉我原因。
【问题讨论】:
-
只需将 'let location = ...' 替换为 'let location = CLLocationCoordinate2D.init(latitude: currentLat!, longitude: currentLong!)' 。您的问题是您添加的是 CGFloats 数组而不是添加 cllocationcoordinate
标签: ios swift annotations polyline cllocation