Insert point into existing routing

I am wondering how to insert a point into an exiting routing the right way. And if there are ways Graphhopper can already handle that. Most likely using the route-optimization api?

So my question it. I have Point A and B and the route Graphhopper provided to get from A to B. Now my user wants to add an other point and I would like not to stupidly append it to the end, but insert it, where it “belongs”. So if the tap of my user would be somewhere in-between, I’d like the new point to be in-between A and B. And if my user taps somewhere further away, it should e.g. append it to the end or insert it as a new start. So do that smarter.

I am mainly fetching for the buzzword to google for. Is it the route-optimization that would do that? Or is it something else? And would there be an option to keep some of my sort-order in place and just insert the newest point accordingly?

Doesn’t Driving Directions - GraphHopper Maps do exactly that? It was first implemented here: Insert via points at closest road segment by easbar · Pull Request #153 · graphhopper/graphhopper-maps · GitHub

Ah… yes… seems so. But is this part of the Javascript Web-UI, right? Is there something like this also inside the Java Code of Graphhopper? But thanks a lot! That already helps a lot. I’d just like to bundle the logic into graphhopper and not the frontend (My App).
Have a great day and thanks!

Yes, this is done in the web UI. There is nothing like this on the server side and I don’t think that would be useful or even possible, because the server side has no knowledge of previous requests. So there is no previous route one could insert another point into. Or maybe I do not understand what you are trying to do.

If you generally want to program some logic that finds the ‘correct’ position of an additional point within a given point list that is of course possible and probably very similar to the JavaScript code.

1 Like

Ok… and this code also takes start and end as given, right? So even when I set a point past the end, it will insert it before the end.
It’s a great starting point though! Thanks a lot!
You don’t know how e.g. Komoot is doing it? Their algorithm seems to be able to handle those situations.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.