title: How to select closest gps coordinate from database?
body: <p>I have table <code>GPS_tbl</code> in mysql database <code>my_db</code>. In <code>GPS_tbl</code> there are four columns <code>1)uid</code> <code>2)latitude</code> <code>3)longitude</code> <code>4)regid</code>. In columns <code>2)latitude</code> <code>3)longitude</code> different values of <code>latitude</code> and <code>longitude</code> are already stored as float, now what i want is when user send his/her <code>gps coordinates in terms of latitude and longitude</code> through <code>POST()</code> compare these user sent coordinate with already stored coordinates in columns <code>2)latitude</code> <code>3)longitude</code> and the coordinate in columns <code>2)latitude</code> <code>3)longitude</code> which is closest to user sent coordinate select the <code>regid</code> against it. Please someone help me how to do this in <code>php</code>.</p>
  
  <p>This is how user is sending his/her GPS coordinates. </p>
  
  <pre><code>    $lati = $_POST['lati'];
      $longi = $_POST['longi'];
      $float_value_of_lati = floatval($lati);
      $float_value_of_longi = floatval($longi);
  </code></pre>
  
  <p>This is <code>GPS_tbl</code> </p>
  
  <pre><code>+--------------+------------+-------------+-------------+
  |     uid      | latitude   | longitude   |   regid     |
  +--------------+------------+-------------+-------------+
  |      1       |  73.3433   |  18.5223    |APA91W-ClDoS |
  |              |            |             |             |
  +--- ----------+------------+-------------+-------------+
  |      2       |  43.3433   |  24.5523    |BON91W-ClDoS |
  |              |            |             |             |
  +--- ----------+------------+-------------+-------------+
  |      3       |  55.3433   |  37.5323    |WCD71P-ClDoS |
  |              |            |             |             |
  +--- ----------+------------+-------------+-------------+
  </code></pre>