title: Distance from point A to B using Google Maps, PHP and MySQL
body: <p>Can anyone please help. I just need a simple script. I have a form posted to another page. two formfields are:</p>
  
  <p>fromaddress and toaddress</p>
  
  <p>The only thing I need is a script that shows me the distance in km and the time it takes using google maps. I have found dozens of scripts but I cannot get it working. The map is already there with this code which seems to work perfect.</p>
  
  <pre><code>&lt;script type="text/javascript" src="//maps.googleapis.com/maps/api/js?key=AIzaSyDdDwV6_l5n2bS3gM6NBCla3RFLtIFc_HE&amp;sensor=false"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;
      var directionDisplay;
      var directionsService = new google.maps.DirectionsService();
      var map;
  
      function initialize() {
          directionsDisplay = new google.maps.DirectionsRenderer();
          var myOptions = {
              zoom: 8,
              mapTypeId: google.maps.MapTypeId.ROADMAP,
          }
          map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
          directionsDisplay.setMap(map);
  
          var start = "&lt;? echo $_POST[fromaddress]; ?&gt;";
          var end = "&lt;? echo $_POST[toaddress]; ?&gt;";
          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);
              }
          });
  
      }
  
      $(document).ready(function(){
          initialize();
      });        
  &lt;/script&gt;
  </code></pre>
  
  <p>But how do i display the distance and the time. Best option is to get it in a php value like:</p>
  
  <pre><code>$distance = some-code;
  $time = some-code-too;
  </code></pre>
  
  <p>Thanks a lot for helping.</p>