<form action="http://maps.google.com/maps" method="get" target="_blank">
<label for="saddr">Enter your location</label>
<input type="text" name="saddr" />
<input type="hidden" name="daddr" value="350 5th Ave New York, NY 10018 (Empire State Building)" />
<input type="submit" value="Get directions" />
</form>
saddr = blank input field for entering START address
daddr = hard-coded END address
Enter an address and press button and a popup window opens with directions. Enter no address, and just a map of the END address opens.
Live Demo
thanks for this snippet,
just used it on a site I maintain for the curling club I belong to, seems to work like a charm, does not require much adjustment to get it working,
nice addition to the list
Al
Funny how this was Just what I needed today! And I wasn’t even looking for it…
– Thanks!
How can I add this to a button that when clicked on pops up the form?
I’d use jQuery. Wrap this in a div with id ‘formpp’ (for form pop up) and then try something like,
$(‘button.popup’).click(function(){
if($(‘#formpp’).is(‘:visible’)){
$(‘#formpp’).hide();
} else {
$(‘#formpp’).show();
}
});
Whenever you click on a with class ‘popup’ now, the ‘formpp’ will appear if it’s hidden, or hide if its visible. You’ll need to make sure you import jQuery into any document you’re working on.
@Troy – The answer to your question is here.
After googling for a week, I frankensteined some js together. After I couldn’t get it to work, I posted it on stackoverflow, and a contributor was nice enough to put on the finishing touches. (I marked the answer correct).
I can’t wait to start school so I can quit groveling in the forums and learn this stuff for real.
Hello Chris and folks!
I really like this stuff ,but I am actually wondering if I can use this for commercial issues. Like a homepage for a restaurant?
Do anybody knows if there a copyright for the goggle-maps stuff?
Greetings from germany, Gourmador.
This is a nice snippet; however, it doesn’t validate with the W3C. Here is one that does:
http://malevolent.com/weblog/archive/2005/05/01/add-google-maps/
It is almost identical; however, lacks the target=”_blank” and wraps the inputs in a p tag to validate.
this is good but wat if we are using google maps in our website
the code of wat get directionsis all about is not clear
hoping a clear solution
Thank you!
It will be great, if possible to open the popping up GoogleMap Window in a Lightbox?
Cheers!
Yeah anyway to have the results in a modal pop up?
This is really great!
I just use that and it works fine in Turkey.
Thank you.
Thanks, I t was very helpful.
How i can show the distance in kilometer?
I am submitting the form in iframe with target attribute of form.
Love this article and feature! I will definitely be using this on any websites that i create in the future.
Thanks you :-)
Great! Thanks.
cool…indeed very cool…i was just surfing your website and found this…next what i copied the code in my notepad and found exactly what i wanted…thank you for guiding me…
HI I like the google navigation form but the form is missing form labels so it wouldnt be read by a screen reader.
Thanks! Great to have the directions widget right on a website rather than having people click around once the get to google maps.
This was exactly what I was looking for. Thank you so much for sharing. You really helped me out.
I want to have people be able to enter their address into a text box, press submit, and then display the results on my own page instead of it going directly to maps.google.com. can this be done?
Is there anyway to display the driving directions on my website after the user submits their address?
Thank you. This is great! I would also love to know how to display the direction results on my webpage after the user submits their address. Just like this website (i know its in dutch but its the only one I came across) Thanks:
http://m.diks.nl/app/vind-ons/664589/2/
Nice, But, i would like to know how it works on a same page rather than being redirecting to the google map url. I am actually looking for map search API.
Hello, I’m trying to use this search box, but I want to do it on a given page, which I have called “Locate”, but I do not get to do it this way, no search box appears where I can enter data. How I can create a search box with HTML to put in these pages that only accept HTML?
Thank you very much!
I love you. Seriously, always great info. Thanks!
Just saved me an hour. Awesome.
I just tried the demo – worked lovely, but said to Fly to London, United Kingdom—New York, NY, round trip $670.
Is this worth paying to come visit you Chris? haha ;)
Thanks for posting this snippet:
saddr = blank input field for entering START address
daddr = hard-coded END address
I had 2 directions boxes and needed to add 2 more.. but the new ones would not work.
When I look closer the editor had added a ‘2’ in the code
saddr2 = daddr2= which cause it to break…. ( its the little things that count!)
It works well with Decimal Latitude and Longitude values :)
… input type=”hidden” name=”daddr” value=”40.7499839,-74.0180638″ …
Perfect, just what I needed. Thank you.
@Raquel am also using lat and lon values. But how i display custom title with lat and lon values because it show these values on title
Very good post! thanks a lot
Super little tool – thanks for having nice simple code to use!
Does anyone know how to change it so that the user can get directions from current location rather than inputting the address?
Love this code super helpful, I have one question though. Is there a way to make the code https instead of http. I want to put it on a https site and when on that site it tells you that you are submitting information to an “unknown 3rd party do you wish to continue”. while I know this code isn’t actually going anywhere except through the code it makes people nervous to see the text pop up.
Figured out my own question. So if you are running a site on https and want to run this code simply change the http in the code to https://maps.google… and continue rest of code as normal.
As long as the user is clicking on the link from a device which provides location (a computer connected to Wi-Fi or a smartphone with location services authorized), the following URL scheme will automatically generate directions without requiring users to input their current location:
https://www.google.com/maps/dir/CURRENT+LOCATION/1234+Address+Avenue+E,+City,+State+77840
By including the string
Current+Location
, Google will fetch current location and generate directions (invoked by the/dir/
prefix) from the user’s current location!This is pretty good code. But is there any way to get the map with the directions to appear in an iframe instead of on a separate web page? I’ve been trying to get it to appear in an iframe but having no luck.
Thanks in advance.
hello,
i new in code html but does someone knows how to use the geolocation browser as saddr ?
thanks