如何将 Postgis 距离添加到结果集中

How do I add the Postgis distance to the result set

这是我当前的查询,目前 returns 符合条件的结果的名称和点按距离排序,我如何将距离也包含在结果集中?

查询:

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注入

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);

但是,对于您的工作地点查询,还应强制转换为地理位置(如果不是)。