mapbox / mapbox/mapbox-directions-swift
Map matching: very difficult to get a route with coordinates
- Dominant language
- Swift
- Stars
- 206
- Forks
- 99
- Avg merge
- 7h 54m
- Merged PRs (30d)
- 3
Description
Hello,
I have a backend where I can trace a route with OSRM. I receive in my iOS app a list of coordinates, from the first to the last location, with all intermediates locations between them.
I calculate the route like this:
```swift
func calculateRoute(locations: [CLLocationCoordinate2D],
completion: @escaping (Route?, Error?) -> ()) {
let matchOptions = NavigationMatchOptions(coordinates: locations, profileIdentifier: .automobile)
matchOptions.includesSteps = true
matchOptions.waypointIndices = IndexSet([0, locations.count - 1])
matchOptions.distanceMeasurementSystem = .metric
Directions.shared.calculateRoutes(matching: matchOptions) { (waypoint: [Waypoint]?, routes: [Route]?, error: Error?) in
completion(routes?.first, error)
}
}
```
But nearly every time, I don't receive any route matching the coordinates:
```swift
routes = nil
```
```swift
Error Domain=MBDirectionsErrorDomain Code=-1 "No matching found" UserInfo={NSLocalizedFailureReason=No matching found}
```
I succeeded one time to receive a valid route (every location perfectly placed on a main street or a road). And when everything seems ok, it often fails.
Is there something i'm doing wrong? Any chances to increase a margin or something else to match a location if it's not perfectly located?
When I calculate routes with waypoints, all works fine but since all waypoints are considered as a place to visit, It's not a workaround for me.
Contributor guide
Research direction
Start with the NavigationMatchOptions setup and Directions.shared.calculateRoutes(matching:) call shown in the issue; inspect the map-matching requirements for supplied coordinates and how the no-match error is surfaced. Reproduce with representative coordinate traces, then document or implement a supported way to handle locations that are not directly on roads.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- api, mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100