mercredi 13 juillet 2016

Selection of locations based on distance between coordinates

I attempt to make a code which calculates the nearest locations for a certain given coordinate. However I got stuck on the following error:

ERROR: column "distance" does not exist  
LINE 5: `HAVING distance < 150`  
in ROOTfrontend3.php on line 16. 

Data is retrieved from pgadminIII database. All help is welcome

<?php 

include 'connection.php';

$lat = $_GET['lat'];
$lng = $_GET['lng'];

#Select inormation from Parking database
$result = pg_query($conn, "
SELECT id, ( 6371 * acos( cos( radians($lat) ) * cos( radians( lat ) ) *     cos( radians( lng ) - radians($lng) ) + sin( radians($lat) ) * sin( radians( lat ) ) ) ) 
AS distance 
FROM parking
HAVING distance < 150 
ORDER BY distance 
LIMIT 10
");
echo $result;

Aucun commentaire:

Enregistrer un commentaire