shinzou
shinzou

Reputation: 6192

Mapbox - Get an accurate road route to display on the map

When we use the directions api over long distances we noticed the lines aren't exactly on the roads, like in this image:

enter image description here

it's from: https://docs.mapbox.com/playground/directions/

coordinates: -86.945145,40.090054;-88.26635,40.136585

I didn't find any way to make the directions API return a more precise path but I saw the matching API so I thought I could use the route I got from the directions API and match it to the roads. The problem is when I use it I encounter the error:

"All coordinates are too far away from each other"

Even when I try to split the route to pairs of two coordinates it still says that. There's no mention of such a limit in https://docs.mapbox.com/api/navigation/#map-matching. The coordinates above return that error.

That's the coordinates I got from directions API so I have no choice but to use them but they're incompatible with matching API, so what can I do to get an accurate directions path that sits exactly on the roads?

I thought about adding midpoints between every pair of coordinates but that won't work in cases where those midpoints would be far off any road.

Upvotes: 0

Views: 1866

Answers (1)

Steve Bennett
Steve Bennett

Reputation: 126255

There are two ways to get more precise geometries from the Directions API:

  • geometries: "polyline6" (get geometries with 6 decimal places of precision)
  • overview: "full" (include full geometry in the overview, not just in the route legs)

I think using those will solve your problem.

Upvotes: 3

Related Questions