ios - MapKit Step折线在哪里?

标签 ios mapkit

我正在尝试打印所有路线步骤的坐标,类似于 Google Maps SDK 的“腿”。

但是它告诉我不能使用polyline 属性来获取坐标?

enter image description here

最佳答案

试试这个:

for step in self.route!.steps as [MKRouteStep] {

否则它将 step 视为 AnyObject(它没有定义 polyline 属性,因此您会收到编译器错误)。


顺便说一下,请注意 polyline.coordinate 只是给出折线或一个端点的平均中心。一条折线可以有多个线段。

如果您需要获取所有沿折线的线段和坐标,请参阅latitude and longitude points from MKPolyline ( objective-C )。

这是一种可能的 Swift 翻译(在 this answer 的帮助下):

for step in route!.steps as [MKRouteStep] {
    let pointCount = step.polyline.pointCount

    var cArray = UnsafeMutablePointer<CLLocationCoordinate2D>.alloc(pointCount)

    step.polyline.getCoordinates(cArray, range: NSMakeRange(0, pointCount))

    for var c=0; c < pointCount; c++ {
        let coord = cArray[c]
        println("step coordinate[\(c)] = \(coord.latitude),\(coord.longitude)")
    }

    cArray.dealloc(pointCount)
}

正如第一个链接答案所警告的那样,根据路线,您每一步可能会获得成百上千个坐标。

关于ios - MapKit Step折线在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28643554/

相关文章:

ios - Restkit - 无法使用 RKDotNetDateFormatter 设置首选输出日期格式化程序

ios - UICollectionView 的大小有时是错误的

ios - 无法添加托管在 OS X Server 上的 Git 存储库

ios - 如何创建具有多列的 TableView

ios - 如何在 Swift (iOS) 中使用 MKSnapshotter

ios - ios:mapKit viewForAnnotation从PIN消失弹出标题?

ios - 向 MapKit 添加多个圆

c# - 在启动 Appium session 之前获取可用设备列表

ios - 使用 mapkit 创建 map ?

swift - 构建包含 MapKit 的应用程序时找不到符号