swift:实时显示mkdirection指令

swift: display mkdirection instructions in real time

使用 mapKit,我想通过显示当前步骤的说明来引导用户上路。因此,一旦该步骤完成,就会为相应的(下一步)步骤更新指令。

据我所知,mapKit 不允许您直接这样做。我找到了 ,但它在 Obj-C 中,我正在使用 swift。到目前为止,我的代码如下所示:

for step in self.carRoute!.steps {
    var laStep: MKRouteStep = step as! MKRouteStep
    var mapPointForEndOfStep: MKMapPoint = laStep.polyline(laStep.polyline.pointCount - 1) as! MKMapPoint
}

但我收到此错误:'(_) -> _' 与 'MKPolyline'

不同

谁知道怎么设置每一步的最后一点?或者是否有某种魔法可以告诉用户正在进行的步骤。或者如果他不在应用程序指示的方向之外?

我自己找到了解决方案。因此,如果有人遇到同样的问题,我翻译了在 swift 中找到的 的 Obj-c 代码:

let thisStep: MKRouteStep = (self.carRoute?.steps[self.stepsCounter])!
let pointsArray = thisStep.polyline.points()
let lastPoint = pointsArray[thisStep.polyline.pointCount - 1]
let theLoc: CLLocationCoordinate2D = MKCoordinateForMapPoint(lastPoint)

self.theRegion = CLCircularRegion(center: theLoc, radius: 50, identifier: "turningPoint")