Map-matching: Allowing U-turns mid-segment for pedestrian profiles (NODE_BASED traversal)

Hi GraphHopper community,

I am currently working on map-matching for pedestrian/hiking traces. I’ve noticed a specific behavior where U-turns in the matched output are always forced at the next real intersection, even when the GPS observations clearly indicate that the user turned back in the middle of a street/path.

After analyzing the source code, I believe I’ve identified the two main reasons for this:

  1. Traversal mode: In MapMatching.java, the routerFromGraphHopper method is hardcoded to use TraversalMode.EDGE_BASED. While this is ideal for vehicles to handle turn restrictions, it seems to prevent the router from performing a 180° turn “on the spot” at a virtual node.

  2. Edge resolution: The prepareEdgeMatches method uses resolveToRealEdge, which maps virtual nodes back to the original edge keys. This ensures results go from intersection to intersection, but it seems to “stretch” the U-turn to the nearest tower nodes.

For a pedestrian, pivoting 180° mid-segment is a natural and frequent behavior. I am considering modifying the code to allow TraversalMode.NODE_BASED when a pedestrian profile is used.

My questions are:

  • Has anyone already experimented with switching the Map-Matching API to NODE_BASED traversal?

  • Would this change be enough to allow the Viterbi algorithm to transition between two virtual edges in opposite directions at the same snap point without routing to the next intersection?

  • Are there any known side effects on the HMM probabilities or the queryGraph logic when forcing NODE_BASED in this context?

I would appreciate any insights or feedback on this approach!

Best regards, Arnaud

We noticed this on several cases a few weeks ago, so we started to find a way to fix this issue, as explained in my first message.
But I just did some new tests and it looks like the mapmatching is making U-turn in middle of path now. Is there a recent issue/change that could explain this (I didn’t find it) ?