0

Currently I have a query that selects all the objects closer than X km from specified GPS coordinations:

$query = 
  'SELECT * FROM t_activity WHERE
   POINT(gps_lat||\',\'||gps_lon) <@> 
   POINT(
     '.$gps_latitude.', 
     '.$gps_longitude.'
   ) <= '.$search_range;

Im not skilled in DBs at all, but I would like to know:

Is it also possible to modify the query in order to sort it from closest to farest results?

Axel Stone
  • 1,521
  • 4
  • 23
  • 43

1 Answers1

1

from your query I assume it should be

$query = 
  'SELECT * FROM t_activity WHERE
   POINT(gps_lat||\',\'||gps_lon) <@> 
   POINT(
     '.$gps_latitude.', 
     '.$gps_longitude.'
   ) <= '.$search_range.'
   ORDER BY POINT(gps_lat||\',\'||gps_lon) <@> 
   POINT(
     '.$gps_latitude.', 
     '.$gps_longitude.'
   )
';
Vao Tsun
  • 47,234
  • 13
  • 100
  • 132