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.

alt text alt text

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. alt text

asked 08 Feb, 21:26

Mukul2990's gravatar image

Mukul2990
11123
accept rate: 0%

edited 08 Feb, 23:07


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.

permanent link

answered 08 Feb, 21:35

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
77.7k886901201
accept rate: 24%

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

(08 Feb, 22:04) Mukul2990

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 called routes, choose the first element of that, and in there you will find a geometry field. Use that.

(08 Feb, 22:15) Frederik Ramm ♦

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.

(08 Feb, 22:34) Mukul2990

Try dropping the steps=true, and add an overview=full. Try the geometries=geojson just to avoid any potential problems with the polyline encoding.

(08 Feb, 22:39) Frederik Ramm ♦

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?

(08 Feb, 23:09) Mukul2990

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.

(08 Feb, 23:13) Frederik Ramm ♦

I plotted this path using geojson as you suggested. Is there other way to validate the lat-longs?

(08 Feb, 23:14) Mukul2990
showing 5 of 7 show 2 more comments
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×73

question asked: 08 Feb, 21:26

question was seen: 647 times

last updated: 08 Feb, 23:14

powered by OSQA