传入的参数
latitude ----------自身位置纬度
longitude --------自身位置经度
id ------------------要查询的那个店铺id

Mapper

Double selectDistanceByLongitudeAndLatitude(@Param("latitude")double latitude, @Param("longitude")double longitude, @Param("id")Long id);

Mybatis中的sql

<select id="selectDistanceByLongitudeAndLatitude" resultType="Double" >
   select ROUND(
       6378.138 * 2 * ASIN(
       SQRT(
       POW( SIN( ( #{latitude} * PI( ) / 180- shop_latitude * PI( ) / 180 ) / 2 ), 2 ) + COS( #{latitude} * PI( ) / 180 ) * COS( shop_latitude * PI( ) / 180 ) * POW( SIN( ( #{longitude} * PI( ) / 180- shop_longitude * PI( ) / 180 ) / 2 ), 2 )
       )
       )* 1000
       ) As distance
       from franchise_store
       where id=#{id}
</select>

返回的是店铺到你自身位置的距离distance(单位:m)

数据库表名
franchise_store

数据库字段
数据库字段

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐