I have an application where the user selects some "markers" from a google maps (all those coordinates' markers are stored into a postgresql database).

Right now, I can draw the route between all selected markers (using DirectionService) but when I have over 10 waypoints the route seems to be drawn in the user selected order (not in the "shortest route" order - I also used optimizeWaypoints parameter to true and split the route into subroutes of 8 points + start and stop points without success). What I`m trying to do now: when the user selects a marker, I save his selection (marker coordinates) and then all selected coordinates are sent (via ajax) to the server.

The received coordinates are in a format something like this:

array((lat1,lng1), (lat2,lng2), ...(latn,lngn))

From here, I want to return back to the user all those coordinates ordered by "shortest path" and I don't know how to achieve this.

Any idea will be great.

  • An illustration could help: in its current form, your question seems to be asking for a solution to the Traveling Salesman Problem, but it is not clear this is what you really need.
    – whuber
    Jun 26, 2013 at 18:08
  • Yes, I think it`s a form of TSP but all my points are not stored into database table. Jun 26, 2013 at 18:19
  • What exactly are you asking for, then? A detailed TSP algorithm? TSP code that you could use? Help in reformatting your points so that they could be read by such code?
    – whuber
    Jun 26, 2013 at 19:20

1 Answer 1


Since you say your markers are stored in a postgresql database, this material will be very useful for you: TSP with pgRouting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.