这是我当前的查询,它当前返回按距离排序的符合条件的结果的名称和点,如何在结果集中包含距离?
查询:
select name, ST_AsText(location) from places where ST_DWithin(
ST_GeogFromText('SRID=4326;POINT($point)'),
location,
$distance
) ORDER BY ST_Distance(
ST_GeogFromText('SRID=4326;POINT($point)'),
location
)
显然, $distance
和$point
需要防范sql注入。
答案 0 :(得分:0)
SELECT name,
ST_AsText(location),
ST_Distance(ST_GeogFromText('SRID=4326;POINT($point)'),location)
FROM places
WHERE ST_DWithin(ST_GeogFromText('SRID=4326;POINT($point)'), location, $distance)
ORDER BY ST_Distance( ST_GeogFromText('SRID=4326;POINT($point)'), location);
但是,对于您的查询工作位置也应该转换为地理位置(如果不是)。