以下是我使用Mapbox进行逐步导航的代码。
let origin = Waypoint(coordinate: currentLocation.coordinate, name: "Your Location")
let pickUpLocation = Waypoint(coordinate: pickUpCoordinate, name: "Pickup Location")
let deliveryLocation = Waypoint(coordinate: dropOffCoordinate, name: "Dropoff Location")
let options = NavigationRouteOptions(coordinates: [origin, pickUpLocation, deliveryLocation])
Directions.shared.calculate(options) { (waypoints, routes, error) in
guard let route = routes?.first, error == nil else {
print(error!.localizedDescription)
return
}
let navigationController = NavigationViewController(for: route, navigationService: navigationService)
self.present(navigationController, animated: true, completion: nil)
}
我放置的航路点的顺序是原点(即用户的当前位置),然后是pickUpLocation和deliveryLocation。因此,我希望第一条路线是从用户的位置到PickUpLocation。但是,有时候,如果我在pickUpLocation附近,并且开始导航,Mapbox会显示从用户位置到deliveryLocation的路线,而跳过pickUpLocation。
如何解决此问题?