当前位置:网站首页>基于ibeacons三点定位(微信小程序)
基于ibeacons三点定位(微信小程序)
2022-04-23 14:02:00 【1029179954】
本文章分享三点定位核心代码,以及在写的过程中发现的问题
1:三点定位,不是有三个ibeacons就可以一定都连接上,在wx.getBeacons({})就会发现轻易很难拿到三个,所以做测试多买几个ibeacons
2:网上几乎三点定位都是利用勾股定理,所以计算动点到定点距离成了关键,有2种方法
(1)这里我使用的是官方提供的距离,小程序接口自身会返回距离,这个应该也考虑rssi的波动和 衰减。
(2)还有就是根据公式测算(我感觉没有微信官方给的准确度高)
var pointBRSSi = res.devices[i].RSSI;
var iRssi = Math.abs(pointBRSSi);
var power = (iRssi-55)/(10*2.0);
var pointBDistance = Math.pow(10, power);
(3)有些代码也是拷贝来的,自己改进,简化了代码,最后一部分往出算x,y坐标的代码我也没有理解,所以最后的结果有误差。下面的代码到现在没有理解 如何计算出的坐标。取01,02,03分别为,(2,0),(2,2),(0,2)固定坐标点,做定位
var pointDX='';var pointDY = '';
var p = Math.pow(pointADistance,2)/10-Math.pow(pointBDistance,2)/10;
pointDX = 2.5 - p;
var m = Math.pow(pointADistance,2)/10-Math.pow(pointCDistance,2)/10;
pointDY = 2.5 - m;
js代码 可以计算出结果 但是误差很大
predict:function(){
var that=this
wx.startBeaconDiscovery({
//设置ibeacons的参数
uuids: ['uuid'],
//连接成功
success: function () {
console.log("开始扫描设备")
//监听iBeacon设备的更新事件
wx.onBeaconUpdate(function (res) {
//获取连接蓝牙设备
wx.getBeacons({
success: (result) => {
console.log("ibacon的个数"+res.beacons.length)
//rssi强度
var arrayRSSI = new Array();
//距离
var arrayaccay = new Array();
//major
var arraymajor = new Array();
//三个定点到动点的距离
var pointADistance = '';
var pointBDistance = '';
var pointCDistance = '';
for(var i = 0; i<res.beacons.length;i++){
//将距离和强度放入数组中major
arrayRSSI.push(Math.abs(res.beacons[i].RSSI));
arrayaccay.push(res.beacons[i].accuracy)
arraymajor.push(res.beacons[i].major)
}
if(arrayaccay.length > 3 || arrayaccay.length==3){
//距离排序
for(var i = 0 ; i < arrayaccay.length ; i ++){
for(var j = i+1 ; j< arrayaccay.length ; j++){
if(arrayaccay[i]<arrayaccay[j]){
var select = arrayaccay[i];
arrayaccay[i] = arrayaccay[j];
arrayaccay[j] = select;
}
}
}
}
//给三个动点赋值
for(var i = 0 ; i < 3; i++){
if(i==0){
pointADistance=arrayaccay[i]
console.log("a距离:"+pointADistance);
}
if(i==1){
pointBDistance=arrayaccay[i]
console.log("b距离:"+pointBDistance);
}
if(i==2){
pointCDistance=arrayaccay[i]
console.log("c距离:"+pointCDistance);
}
}
if(!pointADistance==''&&!pointBDistance==''&&!pointCDistance==''){
var pointDX='';var pointDY = '';
var p = Math.pow(pointADistance,2)/10-Math.pow(pointBDistance,2)/10;
pointDX = 2.5 - p;
var left=pointDX*10+"%"
var m = Math.pow(pointADistance,2)/10-Math.pow(pointCDistance,2)/10;
pointDY = 2.5 - m;
var top=pointDY*10+"%"
console.log('目标所在位置X是'+top);
console.log('目标所在位置Y是'+left);
that.setData({
left:left,
top:top
})
}
},
})
})
},
fail:function(){
wx.showToast({
title: '没进入设备范围',
icon: 'fail',
duration: 500
})
}
}),
//搜索超时 停止扫描设备
setTimeout(function () {
wx.stopBeaconDiscovery({
success: function () {
console.log("停止扫描设备!");
}
});
}, 10000);
},
希望各位大侠可以帮忙解决问题,或者有更好的解决方法可以留言或者私信我。
版权声明
本文为[1029179954]所创,转载请带上原文链接,感谢
https://blog.csdn.net/baidu_38978508/article/details/121730566
边栏推荐
- 项目中遇到的问题(五)操作Excel接口Poi的理解
- nodejs通过require读取本地json文件出现Unexpected token / in JSON at position
- Choreographer full resolution
- 大专的我,闭关苦学 56 天,含泪拿下阿里 offer,五轮面试,六个小时灵魂拷问
- redis如何解决缓存雪崩、缓存击穿和缓存穿透问题
- 3300万IOPS、39微秒延迟、碳足迹认证,谁在认真搞事情?
- 生产环境——
- Yarn online dynamic resource tuning
- Basic knowledge learning record
- New关键字的学习和总结
猜你喜欢
How does redis solve the problems of cache avalanche, cache breakdown and cache penetration
STM32 learning record 0007 - new project (based on register version)
[VMware] address of VMware Tools
smart-doc + torna生成接口文档
freeCodeCamp----arithmetic_ Arranger exercise
What is the difference between blue-green publishing, rolling publishing and gray publishing?
Wechat applet
【报名】TF54:工程师成长地图与卓越研发组织打造
Question bank and answer analysis of the 2022 simulated examination of the latest eight members of Jiangxi construction (quality control)
Quartus prime hardware experimental development (de2-115 board) experiment II function adjustable comprehensive timer design
随机推荐
The art of automation
腾讯根据ip解析地址
redis如何解决缓存雪崩、缓存击穿和缓存穿透问题
_模_板_
json反序列化匿名数组/对象
商家案例 | 运动健康APP用户促活怎么做?做好这几点足矣
AtCoder Beginner Contest 248C Dice Sum (生成函数)
联想产品经理林林:天津当地网络运营商网络故障 ZUI系统后台服务器暂时无法正常工作
nodejs通过require读取本地json文件出现Unexpected token / in JSON at position
Special test 05 · double integral [Li Yanfang's whole class]
可否把模板的头文件和源文件分开编译
JS 烧脑面试题大赏
Record a strange bug: component copy after cache component jump
Spark入门基本操作
[code analysis (3)] communication efficient learning of deep networks from decentralized data
As a junior college student, I studied hard in closed doors for 56 days, won Ali offer with tears, five rounds of interviews and six hours of soul torture
【项目】小帽外卖(八)
Oracle alarm log alert Chinese trace and trace files
2021年秋招,薪资排行NO
STM32学习记录0007——新建工程(基于寄存器版)