title: PHP get current latitude longitude and pass as string to query phpmyadmin database
body: <p>I'm trying to query my database according to current geolocation.
  I have tried to find examples because this is all new to me.
  When I execute this code with the hardcoded values (45.344779 and -73.740337), it gives me the result I expect. I would like to pass the person's current geolocation Latitude and Longitude as string to do the query but it's not working:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;head&gt;
  &lt;title&gt;Current Latitude &amp; Longitude&lt;/title&gt;
  &lt;script&gt;
  if(!navigator.geolocation){
      alert('Your Browser does not support HTML5 Geo Location. Please Use       Newer Version Browsers');
  }
  navigator.geolocation.getCurrentPosition(success, error);
  function success(position){
  var latitude  = position.coords.latitude;   
  var longitude = position.coords.longitude;  
  }
  function error(err){
  alert('ERROR(' + err.code + '): ' + err.message);
  }
  &lt;/script&gt;
  &lt;body&gt;
  
  &lt;?php
  $hostdb = 'localhost';
  $namedb = 'xxxxxx';
  $userdb = 'xxxxxx';
  $passdb = 'xxxxxx';
  
  try {
  $conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);
  $conn-&gt;exec("SET CHARACTER SET utf8");      // Sets encoding UTF-8
  
  $sql="SELECT *,
  SQRT(POW((69.1 * (MyTable.Latitude - :Latitude)) , 2 ) + 
  POW((53 * (MyTable.Longitude - :Longitude)), 2)) AS distance 
  FROM MyTable
  ORDER BY distance ASC 
  LIMIT 3";
  
  $sqlprep = $conn-&gt;prepare($sql);       
  
  $ar_val = array('Latitude'=&gt; 45.344779, 'Longitude'=&gt; -73.740337);
  
  if($sqlprep-&gt;execute($ar_val)) {
  // gets and displays the data returned by MySQL
  while($row = $sqlprep-&gt;fetch()) echo $row['Direction'].' - '.$row['Km'].' : '.$row['Latitude'].' &amp; '.$row['Longitude'].'&lt;br /&gt;';
  }
    $conn = null;        
    }
    catch(PDOException $e) {
    echo $e-&gt;getMessage();
    }
    ?&gt;
  </code></pre>
  
  <p>Any help or hints would be greatly appreciated. Thanks!</p>