Closed camcima closed 1 year ago
Make sure you are handling the escaping in the polyline string correctly - there are backticks and backslashes (\
) that you need to be careful handled when you copy/paste the string. Your symptoms of the string becoming slightly offset at some point kind of points to this kind of error - polyline strings are delta encoded, and it seems likely you've dropped a character which messes up all the subsequent delta values.
In the image "this is the route I'm getting" - you didn't say how you actually generated that map. How did you take the string from the JSON response and pass it to something to render? I suspect the mistake is in that step.
Yes, I've copied and pasted the string from the json response to https://www.freemaptools.com/create-and-plot-encoded-polyline-on-map.htm. I've also tried Google's Polyline Utility (https://developers.google.com/maps/documentation/utilities/polylineutility) and it shows the same deviation.
You can't just copy the value from the JSON and expect it to work - it is a "JSON escaped string" - you need the unescaped string. It is a bit unfortunate that the \
character is a valid symbol in the polyline encoding character set.
You can use a tool like jq
to extract and unescape the string, like this:
curl 'http://localhost:5000/route/v1/driving/-56.187188,-34.891312;-56.199562,-34.905812;-56.187188,-34.891312?overview=full' | jq -r .routes[0].geometry
alternatively, replace all the \\
with \
- those are the escape characters in JSON string encoding. If you do that, you'll see the polyline is correct:
You're absolutely right. I've just tried with a geojson output and it displays the route correctly. Thanks a lot for your prompt response @danpat!
Issue
I'm using a local OSRM docker instance (osrm/osrm-backend:latest) with a uruguay-latest extract downloaded at Geofabrik to create a simple short roundtrip route but there's a weird deviation on the first leg of the route that throws it to a completely wrong path.
This is the route I should get (using OSRM demo site)
This is the route I'm getting.
Steps to reproduce
Please provide the steps required to reproduce your problem.
osrm-backend
version being used: osrm/osrm-backend:latest docker image (v5.25?)If you're reporting an issue with https://map.project-osrm.org, please provide a link to the problematic request.
Specifications
Please provide details of your development environment.