'Route'类型的值没有成员'coordinates'
按照简单的YouTube教程获取此错误。试图画一条路线。有人知道我为什么收到此错误吗?豆荚有问题吗?
这些是已安装的。谢谢!
pod 'Mapbox-iOS-SDK', '~> 5.6'
pod 'MapboxCoreNavigation', :git => 'https://github.com/mapbox/mapbox-navigation-ios.git', :tag => 'v1.0.0-alpha.1'
pod 'MapboxNavigation', :git => 'https://github.com/mapbox/mapbox-navigation-ios.git', :tag => 'v1.0.0-alpha.1'
所以我设法找到了示例应用程序以及错误。
以下是示例应用程序中的代码给出错误为
类型'Route'的值没有成员'coordinates'@routes?.first?.coordinates
Directions.shared.calculate(routeOptions) { (waypoints, routes, error) in
guard let routeCoordinates = routes?.first?.coordinates, error == nil else {
print(error!.localizedDescription)
return
}
//
// ❗️IMPORTANT❗️
// Use `Directions.calculateRoutes(matching:completionHandler:)` for navigating on a map matching response.
//
let matchOptions = NavigationMatchOptions(coordinates: routeCoordinates)
// By default, each waypoint separates two legs, so the user stops at each waypoint.
// We want the user to navigate from the first coordinate to the last coordinate without any stops in between.
// You can specify more intermediate waypoints here if you’d like.
for waypoint in matchOptions.waypoints.dropFirst().dropLast() {
waypoint.separatesLegs = false
}
Directions.shared.calculateRoutes(matching: matchOptions) { (waypoints, routes, error) in
guard let route = routes?.first, error == nil else { return }
// Set the route
self.navigationViewController?.route = route
}
}
必须如下重写。
Directions.shared.calculate(routeOptions) { (waypoints, routes, error) in
guard let firstRoute = routes?.first, let waypoints = waypoints, error == nil else {
print(error!.localizedDescription)
return
}
//
// ❗️IMPORTANT❗️
// Use `Directions.calculateRoutes(matching:completionHandler:)` for navigating on a map matching response.
//
let matchOptions = NavigationMatchOptions(waypoints: waypoints)
// By default, each waypoint separates two legs, so the user stops at each waypoint.
// We want the user to navigate from the first coordinate to the last coordinate without any stops in between.
// You can specify more intermediate waypoints here if you’d like.
for waypoint in matchOptions.waypoints.dropFirst().dropLast() {
waypoint.separatesLegs = false
}
Directions.shared.calculateRoutes(matching: matchOptions) { (waypoints, routes, error) in
guard let route = routes?.first, error == nil else { return }
// Set the route
self.navigationViewController?.route = route
}
}
请检查是否可以解决您的问题
安装在吊舱下面pod'Mapbox-iOS-SDK','〜> 5.2'pod'MapboxNavigation','〜> 0.38.0'
写下面的代码,对我有用
if(CLLocationManager.locationServicesEnabled()){
self.CurrentLat = self.locationManager.location?.coordinate.latitude
self.CurrentLong = self.locationManager.location?.coordinate.longitude
let origin = Waypoint(coordinate: CLLocationCoordinate2D(latitude:
self.CurrentLat, longitude: self.CurrentLong), name: "Start Location")
let destination = Waypoint(coordinate: CLLocationCoordinate2D(latitude: yourDestinationLat,
longitude: yourDestinationLong), name: yourDestinationName)
// Set options
let options = NavigationRouteOptions(waypoints: [origin, destination])
// Request a route using MapboxDirections.swift
Directions.shared.calculate(options) { (waypoints, routes, error) in
guard let route = routes?.first else {
SVProgressHUD.showError(withStatus: "Unable to create a route. Please try
again.")
return
}
let viewController = NavigationViewController(for: route)
viewController.delegate = self
viewController.modalPresentationStyle = .fullScreen
self.present(viewController, animated: true, completion: nil)
SVProgressHUD.dismiss()
}