title: How do I Measure distance using php?
body: <p>I should start of by saying that I'm still pretty green when it comes to PHP, so please be patient with me. I'm trying to figure out the distance between two latitudes and longitudes using php. I found a bunch of scripts online but, however when I try to test them I get the same distance no matter what latitudes and longitudes I use.  I'm sure it's something probably on my part, so I'll just post what I have so far.</p>
  
  <pre><code>$lat1 = "29.140762";
  $lon1 = "-91.639243";
  
  $lat2 = "29.136275";
  $lon2 = "-91.635524";
  
  function distance($lat1, $lon1, $lat2, $lon2, $unit) {
      $theta = $lon1 - $lon2;
      $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
      $dist = acos($dist);
      $dist = rad2deg($dist);
      $miles = $dist * 60 * 1.1515;
      $unit = strtoupper($unit);
  
      if ($unit == "K") {
          return ($miles * 1.609344);
      } else if ($unit == "N") {
          return ($miles * 0.8684);
      } else {
          return $miles;
      }
  }
  
  // Miles
  echo distance(32.9697, -96.80322, 29.46786, -98.53506, "m") . " miles&lt;br&gt;&lt;br&gt;";
  
  //Kilometers
  echo distance(32.9697, -96.80322, 29.46786, -98.53506, "k") . " kilometers&lt;br&gt;&lt;br&gt;";
  
  //Nautical miles
  echo distance(32.9697, -96.80322, 29.46786, -98.53506, "n") . " nautical miles";
  </code></pre>