Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While it does not seem to be documented officially, it looks like you can traverse the response from the <a href="http://code.google.com/apis/maps/documentation/v3/reference.html#DirectionsService" rel="noreferrer"><code>DirectionsService.route()</code></a> method: <code>response.trips[0].routes[0].distance.value</code>, as in the following example:</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;Google Maps JavaScript API v3 Example: Directions Complex&lt;/title&gt; &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body style="font-family: Arial; font-size: 13px; color: red;"&gt; &lt;div id="map" style="width: 400px; height: 300px;"&gt;&lt;/div&gt; &lt;div id="duration"&gt;Duration: &lt;/div&gt; &lt;div id="distance"&gt;Distance: &lt;/div&gt; &lt;script type="text/javascript"&gt; var directionsService = new google.maps.DirectionsService(); var directionsDisplay = new google.maps.DirectionsRenderer(); var myOptions = { zoom:7, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById("map"), myOptions); directionsDisplay.setMap(map); var request = { origin: 'Chicago', destination: 'New York', travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { // Display the distance: document.getElementById('distance').innerHTML += response.routes[0].legs[0].distance.value + " meters"; // Display the duration: document.getElementById('duration').innerHTML += response.routes[0].legs[0].duration.value + " seconds"; directionsDisplay.setDirections(response); } }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Screenshot showing distance and duration: <img src="https://i.imgur.com/Jv9YUkj.png" alt="Google Maps API v3 Directions Demo"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload