Take the 2-minute tour ×

i would like to use Gmap API to calculate the best driving route for many destinations. I have read this page:


That is nearly the same thing i want. However, i only want to get a list of destinations back, that is sorted and tell which destination to go first.

For ex.: I send location of three Destinations A, B , C to Gmap. I need to receive an array like $bestroute[] = {B,C,A}.

I will code with PHP and javascript. If you can help me or know any tutorial, please help.

Thank you very much.

share|improve this question

3 Answers 3

up vote 4 down vote accepted

The link you refer to explains how to do this: admittedly you also get back some directions information you don't care about, but you can simply ignore it.

To be clear, you just make a directions request with some waypoints (say B,C and D) in addition to your origin and destination (A and E).

If using the web service, ensure you set optimize:true before listing your waypoints, and check the waypoint_order array (near the bottom of the result for this url) to get the info you want:


If use the JS API, set optimizeWaypoints:true in your request.

As always, be sure you're abiding by the terms of service (e.g. results from your web service request must be displayed on a Google Map)

share|improve this answer
Thank you very much. –  4everY Aug 6 '12 at 10:14

You might want to look at the Distance Matrix service: https://developers.google.com/maps/documentation/javascript/distancematrix

It gives you distances between a set of origins and destinations, and might help you with narrowing down options.

share|improve this answer

This may be the answer you are looking for as I was having same problem once. Follow the previous post on stack overflow below.

route optimization

share|improve this answer

Your Answer


