My boss has me working on our company Web site and she wants me to add a box on our “contact us” page that lets people type in their address and at the click of a button bring up a window with driving directions from their location to our office. Is that even possible?
Of course it’s possible, anything’s possible on the modern Web! 🙂
There are a lot of different sites that help you with driving directions, but let’s have a look at how Google Maps does it.
The first thing to notice is that you get to the directions aspect of Google Maps by using a slightly different URL: you have to append ?f=d to the end of the URL, like this:
But that’s not quite what we want, really. That lets people enter both the starting and ending point and get directions, but what you seek is something quite a bit more sophisticated.
Nonetheless, the first step is always to enter some data and see what URL is produced (you can unwrap the form, but this is easier). So let’s enter a start and end address and see what Google does with it. It’s not quite that simple, however, because Google’s using various tricks to update material within a page, rather than loading new pages. Fortunately, we can use one of the secondary links to generate a URL. Instead of using “Link to this page”, however, I’ll experiment with something else. Click on the “Send” link and you’ll see a small window pop up:
(A word of explanation is in order here: I entered “start” and “end” as the beginning and ending points of our experimental journey and Google Maps expanded this to “Start, Uninc Richland Parish, LA” and “Vance AFT” (Oklahoma). Why? I have no idea, but it doesn’t really matter, because all we need is the URL from within the message…)
The URL within the message is pretty long:
There’s a lot here that we don’t need, and after a bit of experimentation, the minimum set of fields for the URL are, ready for this?