Optimize Your Trips

A while ago, I made OptiMap, a Google Maps mashup that will take a number of locations and give you the best way to visit all of them. By best, I mean fastest. Since then, I have been exposed to various ideas on applications for this tool. One is in the real-estate business, where prospective home buyers want to visit a number of houses for sale.

To make things easier for anyone interested in applying this tool, there is now a way for your website to make search requests automatically. This is done by sending a http GET request to http://gebweb.net/optimap/index.php?loc0=start&loc1=dest1&loc2=dest2. Here, start should be replaced by the address or (latitude, longitude) pair where your trip starts and ends, and dest1 and dest2 each should be replaced by either an address or a (latitude, longitude) pair you want to visit.

Up to 20 locations can be specified in the variables loc0, loc1, …, loc19. Remember to http-encode any whitespace etc. in your address strings. This is done automatically if you use the html form element to store your data. Example:


<form NAME="roundtrip" METHOD="get" ACTION="http://gebweb.net/optimap/index.php">
<input NAME="loc0" TYPE="text" />
<input NAME="loc1" TYPE="text" />
<input NAME="loc2" TYPE="text" />
<input NAME="loc3" TYPE="text" />
<input TYPE="submit" VALUE="Submit" />
</form>

In some applications, you will not want the user to be typing in addresses himself, so the html form hidden input element may be more suitable than the text input element. The value of such an element can be set with php when the page is created. It can also be changed with JavaScript, with the following code (assuming the form is called “roundtrip”):


document.roundtrip.elements["loc0"].value = "2 Bloor St West, Canada";
document.roundtrip.elements["loc1"].value = "(37.4419,-122.1419)";

If you have any comments, bugs or feature requests, please leave a comment on this site :)

22 Responses to “Optimize Your Trips”

  1. DARREN Says:

    hi, can i contact you via email, i am looking for upto 60 points for an optimised route ?

  2. Keith Soldner Says:

    Great tool. Very cool! Works great when I use it from gebweb.net. I was trying to call it from another web page using your sample code

    http://www.greenthmb.com/route.htm

    When I input four locations and push submit they are properly displayed on the map but there is no route calculated. What am I doing wrong?
    Thanks
    Keith

  3. Russell Says:

    Hi, I really like your page — it’s a great tool. I just have two requests/suggestions:
    -Be able to change the default view to a zip code or city
    -Some sort of print option so that the map is still displayed. As it is, printing will only print the directions, not the map.
    Thanks! Russell

  4. korn Says:

    very nice tool, i am only missing the navigation export :)

  5. geir Says:

    There is navigation export to some extent. The page http://www.gebweb.net/optimap/import.php will give you a text field with exported latitude, longitude pairs.

    Also, for mobile users, I am pleased to confirm to you that OptiMap works with the iPhone and the iPod Touch.

  6. Rob Says:

    Once a route is mapped you are forced to click the ‘Start Over’ button. What if I want to add more locations or remove locations to and from my list? I have to start over again. It would be nice to have a ‘Map Route’ button NEXT to the ‘Start Over’ button instead of having the ‘Start Over’ button replace the ‘Map Route’ button.

    Also, it would be great if I could arbitrarily decide which node is the starting node

    Being able to decide which node is the starting node at any point would be helpful.

    Other than that I have only minor suggestions because this is VERY helpful. I actually use it to map deliveries.

    Rob

  7. Mark Szlazak Says:

    A very good tool! Could it be extended to work with different beginning and end locations for a journey? Here are a couple situations where this could be useful.

    1. Say I go to the office and pick up destinations I have to visit that day but after my last stop, instead of going back to the office, I go home.

    2. Another case is where I initially have the same beginning and end locations for a journey but after making some initial stops, some later stops become canceled. It would be nice if you could then re-compute a new route from my current stop location to the end location that takes into account the changes that result from stop cancellations.

    Thanks.

  8. Mark Szlazak Says:

    I case anyone is interested, the non-roundtrip version of the traveling salesman problem, which has different “start” and “end” stops and involves finding the shortest path through a series of stops in between with only one visit per stop is called the “Hamiltoniam Path Problem.”

  9. Geir Says:

    Russell was asking about printing. I now got it working fairly well. To print, use your browser’s print function (CTRL-P) as you normally would. I recommend using the Opera web browser for optimal results, but Safari works well too. Firefox cannot draw the line that represents the path in the map. As far as I know, no one has gotten that to work for FireFox yet (short of Google, who use a server to generate an image of the map when you click print).

    I don’t have Internet Explorer, so please let me know how it works there.

  10. geir Says:

    Also added functionality to set default map center and zoom level: Use http GET variables center and zoom, e.g http://gebweb.net/optimap/index.php?center=(60,10)&zoom=5

  11. Jeff Torborg Says:

    Dear Geir,

    I am very interested in your optimap technology. Do you provide program consulting services? I am interested in creating a social network using Google Maps and I need help with the development. Please let me know. My email address is (deleted)

    Best Regards,
    Jeff Torborg

  12. maxwellk Says:

    When using the GET request via URL or a form with Safari (v5523.15) it seems to be randomly choosing the start node, and setting loc0 to a random node. Firefox does not seem to have the same problem.

    Great tool, thanks.
    Max

  13. lurlene Says:

    Fantastic! However, on my map, the purple/blue route line is shifted several inches over. Do you know why? Thanks!

  14. Eric Says:

    I just have to say, it’s awesome when you come across exactly what you’re looking for and it turns out someone built it just because they’re intelligent and found it interesting. Many thanks for this!

  15. jon Says:

    Great tool, is it possible to get it to calculate the shortest rather than the fastest

  16. Björn Says:

    I try to use your fantastic library on our website and have two little problems.
    1. When I add a new location only the shadow of the marker is displayed.
    2. Inernet Explorer says “GMap2 is undefined”.
    Everything else is working. Thanks a lot, for that great work.

  17. John Occhi Says:

    Hello,

    I just published a review of your tool on my new blog that focuses on the REO agent community. You can find it here: http://reopro.ning.com/profiles/blog/show?id=2122473%3ABlogPost%3A1538

    Of course I have given you credit and back links to both the tool and your parent company.

    MY question, which I raise in the blog is saving the image. Is there any way to save the image with the pins. Would it be possible to add the address to the pin?

    As an REO AGent, we need to provide reports to the lenders who own the properties and they like to see where the comps are and this would be awesome.

    Perhaps you can leave your comments on my blog, this way I know I’ll see it when you answer.

    Thanks for a great tool. Let me know if there is anything else I can do to help promote the tool.

    John

  18. geir Says:

    A few of you have asked for different starting and ending positions. This is now implemented, with the “A-Z” route option.

  19. Barry Says:

    hello, I was wondering if you were able to get this file directions-export.js and send it to me.

  20. Barry Says:

    never mind about the file, how does TomTom work, is it free. That’s what you use to get the computed data, it gives the directions? is it free to use TomTom?

  21. Matthew Says:

    It seems that the route always goes in the order I place the points on the map and not the optimal route. Am I doing something wrong?

    To test my theory, I clicked on the East coast of the US, then California, then the middle of the US.

    Surely the optimal route would go from East Coast, to the middle to California, but your porgram goes East Coast then California then the middle of the US.

    Cool interface and idea, let me know if I did something wrong.

  22. Arun Says:

    Hello Gier,
    This is Arun from India. We have a similar requirement to be done for India. Will this work for India also? Please help me out in this.
    Regards,
    Arun

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word