1 按照插件
2 数据库导出插件
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
3 更具经度纬度创建 坐标字段
update compass_hospital set coords = st_point( new.longitude , new.latitude) WHERE id = new."id";
4 查询
select *,ST_DISTANCE(coords, ST_POINT( #{longitude} , #{latitude} )) as distance from diagnose_sites_collect ${ew.customSqlSegment} order by ST_POINT( #{longitude} , #{latitude} ) <-> coords
备注:order by ST_POINT( #{longitude} , #{latitude} ) <-> coords 为了挂上索引( 如果 coords 上有索引 )