Calculates the actual distances and excludes the cities that are too far away.
mysql> CREATE TABLE cities (
-> id int(11) ,
-> pt point NOT NULL default '',
-> zip int(11) default NULL,
-> country varchar(10) default NULL,
-> state char(2) default NULL,
-> city varchar(100) default NULL,
-> district varchar(100) default NULL
-> );
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql>
mysql>
mysql>
mysql> SELECT ROUND(SQRT(POW(@x0 - sub.x, 2) + POW(@y0 - sub.y, 2)) / 1000) AS distance,
-> sub.city
-> FROM (SELECT city, X(pt) AS x, Y(pt) AS y FROM cities
-> WHERE MBRCONTAINS(@bbox, pt)) AS sub
-> HAVING distance<=30 ORDER BY distance;
Empty set (0.00 sec)
mysql>
mysql> drop table cities;
Query OK, 0 rows affected (0.00 sec)
mysql>
Related examples in the same category