title: Calculate proximity in php
body: <p>I am trying to write a php function that calculates proximity between two points but I cant get it to work.</p>
  
  <p>I am currently using  a function found here: <a href="http://www.zipcodeworld.com/samples/distance.php.html" rel="nofollow">http://www.zipcodeworld.com/samples/distance.php.html</a></p>
  
  <pre><code>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 == "m") {
      return ($miles * 1.609344)/1000; 
  } 
  else if ($unit == "N") {
    return ($miles * 0.8684);
  } 
  else {
      return $miles;
    }
  }
  </code></pre>
  
  <hr>
  
  <p>My application requires precision down to meters but no matter what I do I dont get correct results.</p>
  
  <p>I get the coordinates from here: <a href="http://itouchmap.com/latlong.html" rel="nofollow">http://itouchmap.com/latlong.html</a></p>
  
  <p>What am I doing wrong? Can you please help me out with this?</p>
  
  <p>Thanks</p>
  
  <p>Mike</p>