title: google directions: how to get transit_details?
body: <p>EDIT: this problem is solved thanks to the help of geocodezip who pointed me the right way in the comments...</p>
  
  <p>problem:
  i want transit-directions from google as plain text and i need the transit_details. i tried adding all variations of stuff like (which does not work):</p>
  
  <pre><code>steps[i].transit.arrival_stop.name
  </code></pre>
  
  <p>solution: most transit routes have the first and last steps walking. in this case, <code>.transit</code> does not exist and produces the error.</p>
  
  <p>i fixed the code below accordingly (which now works).</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
    &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"/&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body style="font-family: Arial; font-size: 12px; color:#FFFFFF;" bgcolor="#202020"&gt;
    &lt;div id="panel" style="width: 300px; float: left;"&gt;&lt;/div&gt;
    &lt;div id="map" style="width: 300px; height: 300px;"&gt;&lt;/div&gt;
    &lt;script type="text/javascript"&gt;
  
    calcRoute();
  
    function calcRoute() {
      var directionsService = new google.maps.DirectionsService();
      var directionsDisplay = new google.maps.DirectionsRenderer();
  
      var map = new google.maps.Map(document.getElementById('map'), {
        zoom: 7,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
      });
  
      directionsDisplay.setMap(map);
  
      var request = {
        origin: 'Potsdamer Platz, 10785 Berlin',
        destination: 'Falckensteinstraße, Berlin',
        travelMode: google.maps.DirectionsTravelMode.TRANSIT,
      };
  
      directionsService.route(request, function(response, status) {
        if (status == google.maps.DirectionsStatus.OK) {
          directionsDisplay.setDirections(response);
          writeDirectionsSteps(directionsDisplay.directions.routes[0].legs[0].steps);
        }
        else {
          console.error('DirectionsStatus is ' + status);
        }
      });
    }
  
    function writeDirectionsSteps(steps) {
      var directions = document.getElementById('panel');
      directions.innerHTML = '';
      for (var i = 0; i &lt; steps.length; i++) {
        directions.innerHTML += '&lt;br/&gt;&lt;br/&gt;' + steps[i].instructions + '&lt;br/&gt;' + steps[i].distance.text;
        if (typeof steps[i].transit !== "undefined") {
          directions.innerHTML += '&lt;br/&gt;' + steps[i].transit.arrival_stop.name;
        }
      }
    }
  
    &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>(code based on: <a href="https://stackoverflow.com/questions/27101782/google-maps-api-v3-how-to-change-the-default-waypoint-markers-in-the-directions/27548085#27548085">Google Maps Api v3: How to change the Default waypoint markers in the Directions (set)Panel?</a>)</p>
  
  <p>any help is appreciated a lot!</p>