0

现在我正在用 Swift 3 做一些不错的事情,我希望:计算 2 个地方之间的路线。我正在使用 Xcode 模拟器。我可以通过汽车、步行或公交来计算它。

这就是我所拥有的:

mapview.delegate = self
let request = MKDirectionsRequest()
request.source = MKMapItem(placemark: MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: 40.203314, longitude: -8.410257), addressDictionary: nil))
    request.destination = MKMapItem(placemark: MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: 40.112808, longitude: -8.498689), addressDictionary: nil))
    request.requestsAlternateRoutes = false
    //request.transportType = .automobile
    request.transportType = .transit

    let directions = MKDirections(request: request)

    directions.calculate { [unowned self] response, error in
        guard let unwrappedResponse = response else { return }

        for route in unwrappedResponse.routes {
            self.mapview.add(route.polyline)
            self.mapview.setVisibleMapRect(route.polyline.boundingMapRect, animated: true)
            print("Distance: \(route.distance/1000) m")
            print("ETA: \(route.expectedTravelTime/60) min")


            for step in route.steps {
                print(step.instructions)
            }


        }

    }

我已经设置了代码,一切都适用于汽车或步行。然而,交通选择并没有做任何事情。

这是为什么?

4

1 回答 1

1

不幸的是,transportType .transit 没有方向,只有 ETA

相关帖子

于 2017-01-27T11:14:13.783 回答