MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
request.source = source;
request.destination = destination;
request.transportType = MKDirectionsTransportTypeAny;
MKDirections *directions = [[MKDirections alloc] initWithRequest:request];
[directions calculateETAWithCompletionHandler:^(MKETAResponse * _Nullable response, NSError * _Nullable error) {
...
}];
首先,response.transportType
这里是MKDirectionsTransportTypeWalking
。为什么选择那个?
其次,我真正想要的是所有3种运输类型的运输时间,即公交,步行和汽车。获得这三种方法的最佳方法是什么?创建3个MKDirectionsRequest对象并使用不同的传输类型运行此代码3次似乎很浪费。当然Apple预计我们需要一种方法来同时获得所有3个吗?
答案 0 :(得分:1)
回答你的第一个问题 -
如果您转到“设置”中的“地图设置”,则首选的传输类型可能已设置为“步行”,这就是您获取步行路线的原因。如果步行时间超过某个阈值,我相信它会覆盖。
第二次尝试使用'|'传递多个选项例如。 MKDirectionsTransportTypeWalking | MKDirectionsTransportTypeDriving。不确定它是否会起作用,但值得一试。还有一点需要注意,MKDirectionsTransportTypeTransit仅支持ETA,不会返回路线。