Google Maps API Tutorial

© 2007, 2008, 2009 Mike Williams

Translate this page:


Get Directions on your own map

It is now possible to obtain directions on your own map.

Here's an example.

There are initially two links: "To here" and "From here". Clicking these links opens a corresponding form.

The initial version of the info window, one with the "To here" form and one with the "From here" form. When the "To here" or "From here" link is clicked, the corresponding html string is loaded into the info window.

When the "Get Directions" button is clicked, the form invokes the "getDirections()" function which makes a GDirections() call.

The details of using GDirections() is well described in the Official Documentation, so I'll not repeat the information here.

From v2.124 you can specify walking directions and avoid highways by using the options {travelMode:G_TRAVEL_MODE_WALKING} and {avoidHighways:true}.

Potential Pitfalls

  1. GDirections() doesn't currently support queries in the form "43.82589,-79.1004(My House)".
    It does support the format "My House@43.82589,-79.1004".
  2. For legal reasons, walking directions don't work if you omit the second parameter when you create the GDirections() object. The API needs somewhere to put the disclaimer.

Here's an example of multi-point routing on your own map.

Back to Mike's Homepage
Up to the start of this tutorial