How to determin relative traffic direction (compared to another vehicle in motion)

Hi all!
Based on GraphHopper and a OSM graph, I’d like to determine if my car is moving in the same traffic direction compared to another vehicle in motion.
That means I need to determine if :

  • the other car is on the same road direction as me, but behind me --> the other car will catch me
  • the other car is on the same road direction as me, but ahead --> I will catch the other car
  • the other car is on the opposite direction (on the same road) and ahead of me --> I will meet the other car

Would you have some ideas to get that?
(Maybe use the history of edges that are crossed by me and the other car? But that does not look easy if I want to detect a potential collision between cars with 10 minutes in advance…)

Thanks guys!

You can grab the historic edges, yes. Or you use the traversal_keys=true parameter. These keys are edges with “direction” (edgeId2+0 and edgeId2 for the opposite direction) and probably better suited for you use case.