views:

63

answers:

1

I'm implementing a Google Map on a website.

One requirement is to display a directions box, which contains the same fields as the one Google Maps uses, and which pops up when the user clicks a button.

I'm aware that the Google Maps API allows you to draw a line between two different locations.

Is it possible to display the directions box itself using the API, rather than coding the box myself?

Please note: I'm referring to the initial directions form - i.e. the form into which you enter the 'A' and 'B' destinations and click 'Get Directions'.

A: 

Yes, the DirectionsRenderer can render the "directions box" automatically. Simply create a <div id="dir_box"> in your HTML and then pass it to your DirectionsRenderer object via the setPanel() method:

directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('dir_box'));

Check out this example from the Google Maps API tutorials for a basic example:

Displaying Google’s ‘directions’ box on a map

Daniel Vassallo
Hi Daniel, thanks for your effort. Unfortunately this seems to be a very minimal rendering - it doesn't even include the 'travel mode' icons (e.g. car, walk, bus).Since it bears almost no resemblance to the Google UI, I might as well just code the elements myself and apply my own styling. I was hoping to avoid this effort, but I guess I can't.
jonathanconway
@jonathanconway: Yes, the API provides everything to build it up yourself. However note that you can still style that panel with CSS styles. The CSS classes that Google uses to render that table appear to be very systematic, and I think basic styling is practical with CSS.
Daniel Vassallo
@Daniel, that's why I'm just doing it myself. What's the point of wasting time with Google's messy markup when it's quicker to write simple HTML and style it myself?
jonathanconway