使用uniapp开发小程序 坐标查询店铺距离位置

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>

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值