Hi, I want to plot detailed map of OSRM's route api response and then compare it with Google Maps. How can I plot the map? I see steps has details of the lat-longs but it's plotting incorrectly. What will be the correct way to plot the map? The "geometry" fields in the response look like this: "kjpfG~{dtL?BDUwAKcLfy@cC|PuAbKy@vHa@rEIhAEz@KpBCz@ErA". I am calling API like this - {{host}}/route/v1/driving/-71.628324,43.178769;-71.979512,43.390553?steps=true I am attacheding OSRM's map and Google Maps Images. It looks OSRM is not plotting it correctly. Can somebody tell me if there is any issue in OSRM server itself or I am not plotting correctly.
Edit - After Frederik Ramm's comment, I plotted the lat-long using OSRM's route API. I see the issue, it's plotting on the wrong side of the road after some time. Need help in understanding what is the exact issue here. Here is the screenshot. asked 08 Feb '21, 21:26 Mukul2990 edited 08 Feb '21, 23:07 |
One Answer:
The geometry in the "geometry" response field is encoded using Google's polyline format. You will need to decode that to get coordinates. There are libraries out there for various programming languages to accomplish that. Alternatively, as per http://project-osrm.org/docs/v5.23.0/api/ you can specify "coordinates=geojson" to receive the coordinates in a GeoJSON format instead. answered 08 Feb '21, 21:35 Frederik Ramm ♦ showing 5 of 7 show 2 more comments |
I can't find geometry field with value "kjpfG~{dtL?BDUwAKcLfy@cC|PuAbKy@vHa@rEIhAEz@KpBCz@ErA" in my response. My response has 11 geometry fields. Which level field of geometry can be used?
I tried this - https://developers.google.com/maps/documentation/utilities/polylineutility
but it's returning incorrect route if compared to Google Maps route for the same lat-long
Sorry for the confusion, you had posted a very long API response that was unreadable, and I reduced that to what I thought was key. For a best-precision result, try passing in the parameter
overview=full
. Then in the response, check for an array calledroutes
, choose the first element of that, and in there you will find ageometry
field. Use that.Thank you for the quick response. I have updated some details in the question. I am still getting wrong path if I plot using geometry field.
Try dropping the
steps=true
, and add anoverview=full
. Try thegeometries=geojson
just to avoid any potential problems with the polyline encoding.Thanks Frederik, I plotted the map, it's going on the wrong side of the highway after lat-long 271. Please check the attached image in the question. Do you know what's wrong here?
I don't know what is wrong but is this still with the polyline, or with GeoJSON? Because polyline AFAIK uses a differential encoding which, if there's a bug, can lead to funny results like the one you have - route somehow jumps to a wrong place, but then continues "as if" on a road. That's why I recommended GeoJSON just to make sure the bug isn't in the polyline decoding.
I plotted this path using geojson as you suggested. Is there other way to validate the lat-longs?