Add Google Maps driving directions to your website

Posted on April 29, 2008 at 5:23 am

I love using Google Maps “Get Directions” feature any time I need to figure how to get from point A to B. It’s one of the best ways to get driving directions in the USA for sure.

So what if you have a wedding website or a MySpace page and you’re throwing a big party, wouldn’t it be nice if your guests could go to your site, type in the address they will be coming from and automatically get directions to the event location!? Not sure what I mean? Type your address in the box below and you’ll get directions from your address to my house:

Enter your starting address:

Cool huh? You can easily create this little form on any website, blog, or anywhere you can put in some HTML code! This is also great for small business web sites as you can throw it up on your contact page and people can get directions quickly, rather than having to copy your address, open a new window, and then type in their starting address.

So how do we go about creating this modified get directions box? Well first, we’ll need to get the correct syntax for the URL that Google uses for directions. Luckily, we can figure that out by getting directions between two places and then clicking on the Send link at the top right.

Here’s what you end up getting:

maps get directios

Notice the link in the email message! That’s what we need! Here’s what the entire link looks like right now:

http://maps.google.com/maps?f=d&hl=en&geocode=&saddr= 6348+Pratt+Dr,+New+Orleans,+LA+70122+(Pratt+Home)&daddr=4601+lennox+blvd,+new+orleans,+la&sll=37.0625,-95.677068&sspn=33.214763,82.265625&ie=UTF8&z=12

Eeeks! That’s pretty long! There are a lot of fields in the URL, such as SADDR (starting address), DADDR (destination address), hl (language), and some more stuff related to the latitude and longitude.

However, you don’t really need all of these fields in order for Google to give you driving directions! All you need is this:

http://maps.google.com/maps?saddr=start&daddr=end

Go ahead and give it a shot. Put in an address in quotes for the starting and ending address and paste the URL into your browser! I replaced start with my home city New Orleans and end with Houston, TX, so this is what my Google Maps directions URL looks like:

http://maps.google.com/maps?saddr=”new orleans, la”&daddr=”houston, tx”

Pretty nifty eh! Isn’t it fun to mess around with these types of things! Ok, so now that we have a URL that we can pass into Google Maps, we need to create a simple form with two fields, one for the starting address and one for the destination address.

If you want people to just type in their address and get directions to your place, then we’ll want the second field to be hidden and already set to the destination address.

<form action=”http://maps.google.com/maps” method=”get” target=”_blank”>
Enter your starting address:
<input type=”text” name=”saddr” />
<input type=”hidden” name=”daddr” value=”6348 Pratt Dr, New Orleans, LA” />
<input type=”submit” value=”get directions” />
</form>

Check out the code above. The first line starts out form and says that when the submit button is clicked, the data should be sent to maps.google.com/maps. The target=blank means that we want the result to open in a new window. Then we have a text box for the starting address, which is blank.

The second text box is hidden and the value is the destination address that we desire. Finally, there is a submit button with the title “Get Directions”. Now when someone types in their address, they’ll get this:

get directions

You can customize the directions and map even more by following the same procedure as I went through above. For example, let’s say you don’t want the default view to be maps, but instead want it to be Satellite and show Traffic. Type in your directions and then press the Satellite and Traffic buttons on the Google map. Next, click on Send and you’ll see the modified URL:

http://maps.google.com/maps?saddr=%22new+orleans,+la%22&daddr=%22houston,+tx%22&ie=UTF8&t=h&z=7&layer=t

Notice the layer=t and t=h fields in the URL. layer=t is for the traffic layer and t=h means satellite in some strange fashion! Just tack those on to your final URL and you’ve now got a highly customized Google Maps Get Directions form on your site! Source: AskDaveTaylor

Have any issues with this, post a comment and I’ll try to help! Enjoy!

» Filed Under Google Software/Tips

Related Posts

Comments

18 Responses to “Add Google Maps driving directions to your website”

  1. MJ said on :

    Really cool feature. I have tried it before, it’s really helpful.

    Thanks.


  2. Aurelius Tjin said on :

    Great post! Thanks for the valuable information and insights you have shared here.


  3. Bollywood Star said on :

    This is my favorite website because there are greatest posts.

    Thanks to all


  4. Bob said on :

    Hi, do you have any idea how to convert a google map to pdf, so I can draw arrows on the maps and make notes? Thanks.


  5. Raymond said on :

    It’s a nice feature which we have recently added to our website.

    I would also very much like to have the option to save the directions as a pdf file and the option to email the directions directly from the website (options: send as link and/or as pdf).

    Thanks for the article.


  6. PNOOZ said on :

    Regarding your PDFs – try CutePDF Writer – http://cutepdf.com
    It’ll print anything as a PDF file on your computer.

    Thanks for the Google map info,… it’s a big help!

    PNOOZ


  7. nick z said on :

    hey man, every time i do this it never works. Does it look different in Dreamweaver when you view it as opposed to when you put it on a remote site? I’m developing a website right now but do not currently have access to the remote server yet.


  8. unRheal said on :

    Cool! Exactly what I was looking for (well, I wanted to send someone a URL with specific starting and destination points, but that’s easy with your info!) Thanks!

    BTW – I won’t be stopping by for tea, and something a bit over 4500 km to your place, I rather suspect the 1 day, 18 hours (no doubt non-stop, probably at the limit) is a bit more than I’m up for at this time.

    Cheers :)


  9. unRheal said on :

    Nick: (you probably already figured it out, but just in case…) I tried copying and pasting the code from this page into the “code” view of a trivial web page in Dreamweaver, and when I tried to preview/debug it I ended up with a strange page with 3 fields and bits of text displayed that didn’t function at all. I’d saved it to an .htm file, so I just directly loaded that file in IE myself with similar results… but when I went “view source” in IE, the problem was clearly that copying and pasting directly from this page had caused the double quote charcters to come up as some fancy slanted quotes that neither firefox nor IE considered to be actual double quotes.

    So I just used a text editor to do a quick search and replace – I selected one of the funky quotes, and copied it, and used that to search “for” and then just put a real double quote character to “replace” and replaced ‘em all, saved it… then re-loaded it back up into Dreamweaver… and *then* it would load/debug in IE and function properly – I actually got directions when I submitted a valid location.

    As I say, you probably got it all figured out already, but maybe this’ll save someone a few minutes of confusion, as I experienced while trying to figure out why the copy-pasted code wasn’t working! ;)


  10. Mars said on :

    Thanks, Works like a gem!! ;0)


  11. Matt said on :

    I adde this feature, and it’s great, but any idea how to add a dropdown for multiple office locations?


  12. mojomonger said on :

    the “t=h” nomenclature translates to “type=hybrid” – google uses HYRBID to describe satellite maps.


  13. mary said on :

    Thanks so much for providing this information!


  14. omar said on :

    this is great!

    just added a Google Map to my wedding website .. thanks a lot!

    special thanks to unRheal as well!! I did the Ctrl + F and replaced the slanting quotes with the right ones.. genious! saved me a lot of time that is for sure!


  15. Joshua said on :

    Is there a way to use this same or similar code and have the page that opens go directly to the printable driving directions with or without the map? or is that something Google would frown on?

    like this link shows

    http://maps.google.com/maps?f=.....c&pw=2


  16. Mike said on :

    Works like a dream, as i live in france, no probs either.

    Excellent

    Many thanks

    Mike


  17. Brad p said on :

    I am looking for a way to have a program send an address to a website that then automatically opens google maps with that address for the destination. For example a dispatcher of a fire call would text or email the address to a website. The destination address shows in on the users screen with the map. The starting gpoint would be the fire station. Does that make sense? Can I do that with what you posted?


    Pingbacks
  1. Add Virtual Earth maps to your website Says:

    [...] I wrote about how you can easily add Google Maps directions to your website, but not everyone likes Google Maps. Virtual Earth is Microsoft’s product to the online mapping [...]

Please post your comments/suggestions!