title: How to calculate the distance between two places using google maps api and php?
body: <blockquote>
    <p><strong>Possible Duplicates:</strong><br>
    <a href="https://stackoverflow.com/questions/2296087/using-php-and-google-maps-api-to-work-out-distance-between-2-post-codes-uk">Using PHP and google Maps Api to work out distance between 2 post codes (UK)</a><br>
    <a href="https://stackoverflow.com/questions/13542052/google-maps-api-get-two-locations-distance-and-plot-on-map">Google Maps API: get two locations distance and plot on map</a>  </p>
  </blockquote>
  
  
  
  <p>I made a interface where a user can insert start and finish address and after submitting I want to get the latitude and longitude of the both addresses and then calculate the distance between them. I have pasted the code below so far I have done:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form method="post" action ="gMap.php?showDistance=1" &gt;
          &lt;table&gt;
              &lt;tr&gt;&lt;td&gt;Start:&lt;/td&gt;&lt;td&gt;&lt;input id="start" type="text"  name='start'/&gt; &lt;/td&gt;&lt;/tr&gt;&lt;/br&gt;
              &lt;tr&gt;&lt;td&gt;Finish:&lt;/td&gt;&lt;td&gt;&lt;input id="finish" type="text" name='finish'/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/br&gt;
              &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;input type="submit" value="Calculate Distance" /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/br&gt;
          &lt;/table&gt;
      &lt;/form&gt;
  &lt;!--  
  &lt;br/&gt;&lt;br/&gt;
  &lt;div id="map" style="width: 500px; height: 350px"&gt;&lt;/div&gt;
  &lt;div id="results" style="width: 500px;"&gt;&lt;/div&gt;
  --&gt;
  &lt;/body&gt;
  &lt;/body&gt; 
  &lt;/html&gt;
  &lt;?php
  if(isset($_GET['showDistance'])) {
  
      if(!empty($_POST['start'])&amp;&amp; !empty($_POST['finish'])){
      $start='';
      $finish='';
      $start=$_POST['start'];
      $finish=$_POST['finish'];
  
      // I want to send start address via this url;
      $startUrl = 'http://maps.google.com/maps/api.............';
      $startData = @file_get_contents($startUrl);
  
      // I want to send finish address via this url;
      $finishUrl = 'http://maps.google.com/maps/api............';
      $finishData = @file_get_contents($finishUrl);
  
      $startResult = explode(",", $startData);
      $finishResult = explode(",", $finishData);
  
      echo "Information about start address:"."&lt;br/&gt;";
      echo $startResult[0]."&lt;br/&gt;"; // status code
      echo $startResult[1]."&lt;br/&gt;"; // accuracy
      echo $startResult[2]."&lt;br/&gt;"; // latitude
      echo $startResult[3]."&lt;br/&gt;";; // longitude
  
      echo "Information about finish address:"."&lt;br/&gt;";
  
      echo $finishResult[0]."&lt;br/&gt;"; // status code
      echo $finishResult[1]."&lt;br/&gt;"; // accuracy
      echo $finishResult[2]."&lt;br/&gt;"; // latitude
      echo $finishResult[3]."&lt;br/&gt;";; // longitude
  
      } else {
      echo "You forget to insert address";
      }
  }  
  ?&gt;
  </code></pre>
  
  <p>Now the problem I am facing is that I don't know how use the google map api url to get the required information from google map. $startUrl and $finishUrl are the two variable of my concern. By the way I haven't written the code for distance calculation because I yet to get the respected latitude and longitude values.</p>