Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match.tracepoints is inaccurate when there are submatches #386

Open
1ec5 opened this issue Nov 3, 2019 · 0 comments
Open

Match.tracepoints is inaccurate when there are submatches #386

1ec5 opened this issue Nov 3, 2019 · 0 comments

Comments

@1ec5
Copy link
Contributor

1ec5 commented Nov 3, 2019

When none of the input coordinates in MatchOptions separates legs, and the Map Matching API isn’t confident about a match between two input coordinates, it terminates one match at the first input coordinate, adds multiple “submatches” to the next input coordinate, and finally adds a match from that input coordinate onward.

This library gained Map Matching API compatibility to support a “Bring Your Own Route” workflow in which the API’s response is converted into Route objects, as if it came from the Directions API. The assumption is that each match spans the entire distance between the first and last input coordinates, but that isn’t necessarily what the API returns. If the API returns submatches, every Match object’s tracepoints property is inaccurate and there’s no way to reconstruct what the tracepoints should be.

let tracepoints = (json["tracepoints"] as! [Any]).map { api -> Tracepoint in
guard let api = api as? JSONDictionary else {
return Tracepoint(coordinate: kCLLocationCoordinate2DInvalid, alternateCount: nil, name: nil)
}
let location = api["location"] as! [Double]
let coordinate = CLLocationCoordinate2D(geoJSON: location)
let alternateCount = api["alternatives_count"] as! Int
let name = api["name"] as? String
if let waypointIndex = api["waypoint_index"] as? Int {
waypointIndices.insert(waypointIndex)
}
return Tracepoint(coordinate: coordinate, alternateCount: alternateCount, name: name)
}
let matchings = (json["matchings"] as? [JSONDictionary])?.map {
Match(json: $0, tracepoints: tracepoints, waypointIndices: waypointIndices, matchOptions: self)
}

Each match’s array of tracepoints should be filtered down to just the tracepoints whose matchings_index corresponds to the match. It may also help to assert that the waypoint_index increases monotonically.

/cc @mapbox/navigation-ios

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants