获取附近多少米以内的建筑物信息

咱们有时候在业务中可能有一个这种需求,假如获取附近某个点位多少米范围内的建筑信息列表,能够这么作!!!MYSQL给咱们提供了一个st_distance这个函数,能够很方便的使用!html

一、表结构(production_base)git

ID 名称 经度 纬度
id name latitude longitude

二、mybatis映射信息mybatis

<!-- 获取附近多少米的建筑物列表 --> 
<select id="selectNearByProductionList" resultMap="NearByProductionListMap"> 
  select id, name,
(st_distance(point(#{lat,jdbcType=DOUBLE},#{lng,jdbcType=DOUBLE}),point(latitude,longitude))*111195) as distance from production_base 
   <where> 
      (st_distance(point(#{lat,jdbcType=DOUBLE},# 
      {lng,jdbcType=DOUBLE}),point(latitude,longitude))*111195) < #{maxDistance,jdbcType=DOUBLE} 
   </where> 
</select>

其中lat,lng,maxDistance是咱们传递进来的数据,筛选离经纬度lat,lng距离maxDistance的数据信息函数

参考文档:https://www.cnblogs.com/zrbfree/p/5566514.htmlspa

相关文章
相关标签/搜索