title: Google Maps API v3: Driving directions over a map which first loads 2 positions
body: <p>I have a map which displays two locations with markers (and automatically centers between these 2 locations), you can see it live here: <a href="http://goo.gl/rRDCE" rel="nofollow">http://goo.gl/rRDCE</a>
  I'm trying to integrate it with the Directions service, exactly like this demo: <a href="https://developers.google.com/maps/documentation/javascript/examples/directions-simple" rel="nofollow">https://developers.google.com/maps/documentation/javascript/examples/directions-simple</a></p>
  
  <p>The map should first load the 2 locations markers and then if a user select a start point it should show directions to one of the 2 locations.</p>
  
  <p>Here's what I have so far (of course doesn't work, the map isn't loaded)... :P
  <a href="http://jsfiddle.net/multiformeingegno/fhAJA/5/" rel="nofollow">http://jsfiddle.net/multiformeingegno/fhAJA/5/</a></p>
  
  <p><strong>JAVASCRIPT</strong></p>
  
  <pre><code>var directionsDisplay;
  var directionsService = new google.maps.DirectionsService();
  var map;
  
  function initialize() {
      directionsDisplay = new google.maps.DirectionsRenderer();
  var locations = [
      ['Place 1', 41.897467, 12.470364, 2],
      ['Place 2', 41.896561, 12.467792, 1]
  ];
  
      var infowindow = new google.maps.InfoWindow();
  
      var bounds = new google.maps.LatLngBounds();
  
      for (i = 0; i &lt; locations.length; i++) {
          marker = new google.maps.Marker({
              position: new google.maps.LatLng(locations[i][1], locations[i][2]),
              map: map
          });
  
          bounds.extend(marker.position);
  
          google.maps.event.addListener(marker, 'click', (function (marker, i) {
              return function () {
                  infowindow.setContent(locations[i][0]);
                  infowindow.open(map, marker);
              }
          })(marker, i));
      }
  
      map.fitBounds(bounds);
  
      var listener = google.maps.event.addListener(map, "idle", function () {
          map.setZoom(17);
          google.maps.event.removeListener(listener);
      });
  
      directionsDisplay.setMap(map);
  }
  
  function calcRoute() {
      var start = document.getElementById('start').value;
      var end = document.getElementById('end').value;
      var request = {
          origin: start,
          destination: end,
          travelMode: google.maps.DirectionsTravelMode.DRIVING
      };
      directionsService.route(request, function (response, status) {
          if (status == google.maps.DirectionsStatus.OK) {
              directionsDisplay.setDirections(response);
          }
      });
  }
  
  google.maps.event.addDomListener(window, 'load', initialize);
  </code></pre>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"&gt;&lt;/script&gt;
  &lt;b&gt;Start: &lt;/b&gt;
  
  &lt;select id="start" onchange="calcRoute();"&gt;
      &lt;option value="chicago, il"&gt;Chicago&lt;/option&gt;
      &lt;option value="st louis, mo"&gt;St Louis&lt;/option&gt;
      &lt;option value="joplin, mo"&gt;Joplin, MO&lt;/option&gt;
      &lt;option value="oklahoma city, ok"&gt;Oklahoma City&lt;/option&gt;
      &lt;option value="amarillo, tx"&gt;Amarillo&lt;/option&gt;
      &lt;option value="gallup, nm"&gt;Gallup, NM&lt;/option&gt;
      &lt;option value="flagstaff, az"&gt;Flagstaff, AZ&lt;/option&gt;
      &lt;option value="winona, az"&gt;Winona&lt;/option&gt;
      &lt;option value="kingman, az"&gt;Kingman&lt;/option&gt;
      &lt;option value="barstow, ca"&gt;Barstow&lt;/option&gt;
      &lt;option value="san bernardino, ca"&gt;San Bernardino&lt;/option&gt;
      &lt;option value="los angeles, ca"&gt;Los Angeles&lt;/option&gt;
  &lt;/select&gt; &lt;b&gt;End: &lt;/b&gt;
  
  &lt;select id="end" onchange="calcRoute();"&gt;
      &lt;option value="41.897467, 12.470364"&gt;Place 1&lt;/option&gt;
      &lt;option value="41.896561, 12.467792"&gt;Place 2&lt;/option&gt;
  &lt;/select&gt;
  &lt;div id="map" style="position:relative;width:500px;height:300px"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>What am I doing wrong? :)</p>