postgres 坐标

 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 上有索引 )

posted on 2020-11-12 16:59  zhangyukun  阅读(321)  评论(0编辑  收藏  举报

导航