title: how to get accurate or (near accurate) distance between two places? Mysql/PHP
body: <p>SELECT postcode, lat, lng,
      truncate(
          (degrees(acos
              (sin(radians(<code>lat</code>)) 
                  * 
                  sin( radians('.$latitude.')) 
                  + 
                  cos(radians(<code>lat</code>)) 
                  * 
                  cos( radians('.$latitude.')) 
                  * 
                  cos( radians(<code>lng</code> - ('.$longitude.'))) 
                  ) 
              ) 
              * 69.172), 2) 
              as distance
              FROM <code>myData</code><br>
  This query calculates distance (in miles). But when I check distance for same lat and longitude at google maps my result doesnt match. If the distance is around 10 miles then my result is a bit accurate, but over that it gets wrong (for example, my result showed 13 miles and google showed 22 miles for same post code values) </p>
  
  <p>I got this query from <a href="http://forums.mysql.com/read.php?23,3868,3868#msg-3868" rel="nofollow noreferrer">http://forums.mysql.com/read.php?23,3868,3868#msg-3868</a></p>
  
  <p>How can I get it accurate. Any ideas?
  Thanks for help.</p>
  
  <p>UPDATE</p>
  
  <p>I tried @Blixt code in PHP. Picked up 2 sample postcodes and their lats longs</p>
  
  <pre><code>//B28 9ET
  $lat1 = 52.418819;
  $long1 = -1.8481053;
  
  //CV5 8BX
  $lat2 = 52.4125573;
  $long2 = -1.5407743;
  
  $dtr = M_PI / 180;
  $latA = $lat1 * $dtr;
  $lonA = $long1 * $dtr;
  $latB = $lat2 * $dtr;
  $lonB = $long2 * $dtr;
  $EarthRadius = 3958.76; //miles
  echo $distance = $EarthRadius * acos(cos($latA) * cos($latB) * cos($lonB - $lonA) + sin($latA) * sin($latB));
  </code></pre>
  
  <p>Results:</p>
  
  <p>My app - 12.95 miles</p>
  
  <p>Google - 17.8 miles</p>
  
  <p>Any ideas how to get it right?</p>