title: Fastest Way to Find Distance Between Two Lat/Long Points
body: <p>I currently have just under a million locations in a mysql database all with longitude and latitude information.</p>
  
  <p>I am trying to find the distance between one point and many other points via a query. It's not as fast as I want it to be especially with 100+ hits a second.  </p>
  
  <p>Is there a faster query or possibly a faster system other than mysql for this? I'm using this query:</p>
  
  <pre><code>SELECT 
    name, 
     ( 3959 * acos( cos( radians(42.290763) ) * cos( radians( locations.lat ) ) 
     * cos( radians(locations.lng) - radians(-71.35368)) + sin(radians(42.290763)) 
     * sin( radians(locations.lat)))) AS distance 
  FROM locations 
  WHERE active = 1 
  HAVING distance &lt; 10 
  ORDER BY distance;
  </code></pre>
  
  <p><em>Note: The provided distance is in <strong>Miles</strong>. If you need <strong>Kilometers</strong>, use <code>6371</code> instead of <code>3959</code>.</em></p>