传输MKDirectionsRequest产生空错误Error Domain = MKErrorDomain Code = 5&“(null)& quot;

编程入门 行业动态 更新时间:2024-10-12 20:24:28
本文介绍了传输MKDirectionsRequest产生空错误Error Domain = MKErrorDomain Code = 5&“(null)& quot;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用MapKit方向请求获取两个坐标之间的公交路线.

I'm trying to use the MapKit Directions Request to get transit directions between two coordinates.

当我切换到其他(非Transit)类型时,下面的代码有效,但是当我切换到Transit时,它将引发一个错误,该错误在Apple文档中均未显示.

When I switch to other (non-Transit) types, the code below works, but when I switch to Transit, it throws an error that doesn't show up anywhere in Apple's documentation.

这两个位置(来源和目的地)都在纽约市,因此肯定应该有公交路线可用.

The two locations (source and destination) are both in New York City so there should definitely be transit directions available.

错误消息:

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) } } } }

关于我在特定运输案例中可能做错了什么的任何建议?谢谢!

Any advice on what I might be doing wrong for the particular Transit case? Thank you!

推荐答案

当前不支持路线选择路线(iOS 9).如您所见, MKDirectionsRequest 将返回空错误.

Routing directions for transit is currently not supported (iOS 9). MKDirectionsRequest will return a null error, as you observed.

这似乎仅直接记录在MapKit的标题中.看一下 Transit 类型的注释.

This only seems to be documented directly in MapKit's headers. Take a look at the comment for the Transit type.

// 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 } }

更多推荐

传输MKDirectionsRequest产生空错误Error Domain = MKErrorDomain Code = 5&“(null)&

本文发布于:2023-11-26 20:34:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635097.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   Domain   Error   MKDirectionsRequest   MKErrorDomain

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!