我正在尝试使用MapKit路线请求来获取两个坐标之间的传输方向。
当我切换到其他(非Transit)类型时,下面的代码可以工作,但是当我切换到Transit时,它会抛出一个错误,该错误不会出现在Apple的文档中。
这两个地点(来源和目的地)都在纽约市,因此肯定有可用的公交路线。
错误讯息:
Error Domain=MKErrorDomain Code=5 "(null)"
代码段:
override func viewDidLoad() {
super.viewDidLoad()
let request = MKDirectionsRequest()
// Set request parameters
request.source = MKMapItem(placemark: MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: 40.7127, longitude: -74.0059), addressDictionary: nil))
request.destination = MKMapItem(placemark: MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: 40.6761, longitude: -73.9521), addressDictionary: nil))
request.requestsAlternateRoutes = true
// Set tranport type parameter (anything other than .Transit works)
request.transportType = .Transit
let directions = MKDirections(request: request)
directions.calculateDirectionsWithCompletionHandler { response, error in
print(response)
guard let routes = response?.routes else {
print(error?.description)
return
}
// Prints step-by-step directions
for r in routes {
print("New route")
for step in r.steps {
print(" " + step.instructions)
}
}
}
}
对于特定的Transit案件我可能做错了什么建议?谢谢!
答案 0 :(得分:5)
目前不支持传输的路由指示(iOS 9)。正如您所观察到的,Transit
将返回null错误。
这似乎只是直接记录在MapKit的标题中。请查看// MKDirectionsTypes.h
@available(iOS 7.0, *)
public struct MKDirectionsTransportType : OptionSetType {
public init(rawValue: UInt)
public static var Automobile: MKDirectionsTransportType { get }
public static var Walking: MKDirectionsTransportType { get }
@available(iOS 9.0, *)
public static var Transit: MKDirectionsTransportType { get } // Only supported for ETA calculations
public static var Any: MKDirectionsTransportType { get }
}
类型的评论。
@Post("/meetings/{meetingId}/extend")
Call<ExtendMeetingResponse> patchExtendMeeting(
@Header("Authorization") String accessToken,
@Path("meetingId") Integer meetingId,
@Query("duration") Integer duration,);