1、uniapp自带的地图所得经纬度有偏差(只是在开发的时候有偏差,实际在手机上是ok的),
uni.getLocation({
type: 'gcj02',
success(res){
// console.log('latitude 纬度:' + res.latitude);
// console.log('longitude 经度:' + res.longitude);
that.latitude = res.latitude
that.longitude = res.longitude
uni.setStorageSync('latitude', res.latitude);
uni.setStorageSync('longitude', res.longitude);
},
fail(e) {
uni.showModal({
title: '温馨提示', content: '您已未开启定位,请开启', confirmText: '去设置',
success(res){
if (res.confirm) {
uni.openSetting()
}
}
})
}
})
2、mybatis查询距离,并排序
<!-- 获取店铺列表 -->
<select id="getShopListByPage" parameterType="java.util.Map" resultMap="shopMap">
select *, (
6371 * acos (
cos ( radians( #{latitude} ) )
* cos( radians( s.latitude ) )
* cos( radians( s.longitude ) - radians( #{longitude} ) )
+ sin ( radians( #{latitude} ) )
* sin( radians( s.latitude ) )
)
) as distance
from shop_tbl as s
<!-- 搜索范围-->
<if test="range != '' and range != null">
HAVING #{range} > distance
</if>
order by distance DESC
limit #{offset, jdbcType=INTEGER}, #{limit, jdbcType=INTEGER}
</select>