传入的参数
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
数据库字段