mapbox / mapbox-directions-swift

Traffic-aware directions and map matching in Swift on iOS, macOS, tvOS, watchOS, and Linux
https://www.mapbox.com/navigation/
ISC License
186 stars 90 forks source link

Initial point from the response is different than first from waypoint #407

Open twprzybysz opened 4 years ago

twprzybysz commented 4 years ago

Steps to reproduce:

let coordinates = [
CLLocationCoordinate2D(latitude : 32.892264999999995, longitude : 13.177763000000002), 
CLLocationCoordinate2D(latitude : 32.89241945002732, longitude : 13.177979323297292), 
CLLocationCoordinate2D(latitude : 32.89113899999998, longitude : 13.208977000000008)
]
let waypoints = coordinates.map { Waypoint(coordinate: $0, coordinateAccuracy: -1) }
let options = NavigationRouteOptions(waypoints: waypoints, profileIdentifier: .walking)
Directions.calculate(options) { _, routes, error in
    let route = routes.first  // api returns only one route
    print(route.coordinates)
}

Expected behavior First point from returned route is first coordinate.

Actual behavior First point from returned route is second coordinate.

  ▿ 0 : CLLocationCoordinate2D
    - latitude : 32.893127
    - longitude : 13.178129
  ▿ 1 : CLLocationCoordinate2D // I assume that some interpolation is done here
    - latitude : 32.892265
    - longitude : 13.177763
  ▿ 2 : CLLocationCoordinate2D
    - latitude : 32.892295000000004
    - longitude : 13.177812000000001
  ▿ 3 : CLLocationCoordinate2D
    - latitude : 32.892314000000006
    - longitude : 13.177851
  ▿ 4 : CLLocationCoordinate2D
    - latitude : 32.89238700000001
    - longitude : 13.178065
  ▿ 5 : CLLocationCoordinate2D
    - latitude : 32.89241400000001
    - longitude : 13.178136
 (...)

Configuration Mapbox-iOS-SDK: 5.4.0 Mapbox Navigation 0.38.1 iOS versions: 13.3 Device/simulator models: all Xcode version: 11.3

1ec5 commented 4 years ago

I assume that some interpolation is done here

As long as options.routeShapeResolution is full (which is the default), route.coordinates should contain many more coordinates than the coordinates that you converted into waypoints. Waypoints are the locations you know in advance that you want the user to visit, whereas route.coordinates contains enough coordinates for you to know how the user will need to travel to get from one waypoint to the next.

In general, the additional coordinates aren’t due to interpolation; rather, each coordinate is supposed to correspond to a node along a way in OpenStreetMap. OSM may insert a node for many reasons, not necessarily due to the road’s geometry.

However, the Directions API doesn’t appear to be returning the expected results in this area. The first two waypoints are very close to each other and should get snapped to different points along Via Cosenza. Here’s how the OSRM-powered FOSSGIS Routing Service routes between the first two waypoints:

osrm

By contrast, this request returns an unexpected geometry that starts with a spurious coordinate corresponding to the end of Via Cosenza:

valhalla

The mapbox/driving profile returns the same result as OSRM, but the mapbox/cycling profile returns a zero-length geometry at the destination waypoint.

/cc @mapbox/directions-traffic-and-data

twprzybysz commented 4 years ago

@1ec5 any update on this?

1ec5 commented 4 years ago

I’ve reported the issue to the backend routing team to investigate the issue. Unfortunately, there’s nothing we can do on the client side to work around the issue.

Do you see a similar issue with other roads in Tripoli, or just this particular road?

twprzybysz commented 4 years ago

@1ec5 so far only this one.