mapbox - NavigationViewController 的问题 - SwiftUI
问题描述
我成功地生成了一个通用的 MGLMapView 和带有生成路线的折线叠加层,但是在为我的 Turn-by-Turn Directions 功能构建 NavigationViewController 时遇到了障碍。我编译并运行以下代码:
struct MapboxNavigationView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> NavigationViewController {
var viewController: NavigationViewController
let directions = Directions(credentials: DirectionsCredentials(accessToken: "***PrivateKey***", host: nil))
let waypoints2 = [
Waypoint(coordinate: CLLocationCoordinate2D(latitude: 32.623251, longitude: -117.134877), coordinateAccuracy: 1, name: "Origin"),
Waypoint(coordinate: CLLocationCoordinate2D(latitude: 32.672401, longitude: -117.166996), coordinateAccuracy: 1, name: "Destination"),
]
var route = Route?
let options = RouteOptions(waypoints: waypoints2, profileIdentifier: .automobile)
options.includesSteps = true
directions.calculate(options) { (session, result) in
switch result {
case .failure(let error):
print("error = \(error.localizedDescription)")
case .success(let response):
route = response.routes?.first
}
}
viewController = NavigationViewController(for: route, routeOptions: options)
viewController.modalPresentationStyle = .fullScreen
return viewController
}
func updateUIViewController(_ uiViewController: NavigationViewController, context: Context) {
}
}
我在 RouteProgress.swift (MapboxCoreNavigation CocoaPods) 的第 183 行(下方)收到一条错误消息,“线程 1:EXC_BAD_ACCESS(代码=1,地址=0x77797ced916870)”:
self.currentLegProgress = RouteLegProgress(leg: route.legs[legIndex], stepIndex: 0, spokenInstructionIndex: spokenInstructionIndex)
我怀疑 NavigationController 需要访问用户在路线中所在的当前支路。任何帮助将不胜感激!
解决方案
推荐阅读
- sharepoint - Microsoft Graph 调用 PATCH(更新)列表项字段是否区分大小写?
- c++ - 用于数组/向量的 C++ SFINAE
- visual-studio - Intellisense 抱怨“命名空间标准没有成员 size_t”。如何消除此(错误)错误?
- javascript - 在 Django 中的 Ajax 中传递花括号数据
- java - 如何在 iText Java 中的 ColumnText 之后添加段落?
- airflow - 无法在气流 dag 中使用 python 模块
- python - 如何对最后n列进行分组和求和
- c# - UWP XAML 自定义命令栏切换按钮
- ios - WKWebView 视频播放器替换 UINavigationController
- r - 在R中添加共享相同日期的不同行的数据