类型为“Route”的值没有成员“coordinates”
在学习简单的youtube教程时遇到了这个错误。试着画一条路线。有人知道我为什么会收到这个错误吗?是pods的问题吗?
这些都是安装好的。谢谢!
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'发布于 2020-01-27 12:50:45
所以我设法找到了示例应用程序和错误。
以下是示例应用程序中的代码,它给出的错误为
‘
’类型的coordinates值没有成员'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
}
}请检查这是否解决了您的问题
发布于 2020-01-27 13:02:21
安装在pod下方
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()
}https://stackoverflow.com/questions/59924197
复制相似问题