I am using MapBox (Direction API) for drawing routes between two points. When I draw a root on the map on the Mapbox site I got the correct route, however when I use MapboxDirection API (MapboxDirections.swift) ON iOS I got a wrong route (it simply shortcuts the route instead of a turn. URL: https://api.mapbox.com/v4/directions/mapbox.driving/58.3492489633563,37.898002422381;58.3578,37.8787.json?access_token=pk .****&alternatives=true&geometry=polyline
directions!.calculateDirectionsWithCompletionHandler { (response, error) in
if let route = response?.routes.first {
print("Route summary:")
let steps = route.legs.first!.steps
print("Distance: \(route.distance) meters (\(steps.count) route steps) in \(route.expectedTravelTime / 60) minutes")
for step in steps {
print("\(step.instructions) \(step.distance) meters")
self.calculatedTour.append(step)
self.calculatedTourPoints.append(step.maneuverLocation)
}
self.tourLine = MGLPolyline(coordinates: &self.calculatedTourPoints, count: UInt(self.calculatedTour.count))
self.mapView.addAnnotation(self.tourLine)
} else {
print("Error calculating directions: \(error)")
}
}
This appears to be an unintentional over-simplification of the route.
MapboxDirections.swift master
renders this route correctly, however:
the problem has been resolved
for geoCoordinates in route.geometry {
self.calculatedTourPoints.append(geoCoordinates)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.