i am using drupal 6 gmap and location module to save the users latitude and longitude in database. I need to create a service in which i am returned the places list in the order of nearest first. I have all the rest of the code ready and would be all set to go if you guys could share the SQL
Here is some SQL I use to achieve something like this:
$sql = "SELECT zip_code, lat, lon, SQRT( POW( 69.1 * ( lat - " . $this->session->userdata['latitude'] . " ) , 2 ) + POW( 69.1 * ( " . $this->session->userdata['longitude'] . " - lon ) * COS( lat / 57.3 ) , 2 ) ) AS distance FROM zip_code ORDER BY distance ASC LIMIT 1";
This is hitting a table with rows like:
zip_code | lat | lon 12345 | 40.2 | -92
So you would need to amend for your table.