Evening,
I have a PHP script that is selecting results and attempting to filter those results based on a certain distance in miles. I have a database of results, which includes longitude and latitude data collected from Google Maps.
My query currently looks like this...
$stmt = $pdo->prepare("SELECT *,
(((acos(sin(('$latitude'*pi()/180))
* sin((latitude*pi()/180))
+ cos(('$latitude'*pi()/180))
* cos((latitude*pi()/180))
* cos((('$longitude' - longitude)*pi()/180))))
* 180/pi()) * 60 * 1.1515) AS distance
FROM directory
HAVING distance <= '$distance'
ORDER by distance ASC");
The query is returning data. However, it does not seem to filter accurately. My $distance
variable is currently set to 10, so I am hoping only results within 10 miles will be returned.
Does anyone know what is going wrong here?
Thanks, Luke