当前位置:网站首页>基于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
边栏推荐
- 大专的我,闭关苦学 56 天,含泪拿下阿里 offer,五轮面试,六个小时灵魂拷问
- Redis docker 安装
- 生产环境——
- Android: answers to the recruitment and interview of intermediate Android Development Agency in early 2019 (medium)
- MySQL 修改主数据库
- The art of automation
- Spark入门基本操作
- try --finally
- 基础知识学习记录
- Quartus prime hardware experimental development (de2-115 board) experiment 1 CPU instruction calculator design
猜你喜欢
scikit-learn构建模型的万能模板
SQL数据库
CentOS mysql多实例部署
Quartus prime hardware experimental development (de2-115 board) experiment 1 CPU instruction calculator design
Elmo (bilstm-crf + Elmo) (conll-2003 named entity recognition NER)
Neuron and neural network
【报名】TF54:工程师成长地图与卓越研发组织打造
Decentralized Collaborative Learning Framework for Next POI Recommendation
初探 Lambda Powertools TypeScript
Android interview theme collection
随机推荐
Spark入门基本操作
Kettle--控件解析
STM32学习记录0007——新建工程(基于寄存器版)
Special test 05 · double integral [Li Yanfang's whole class]
JS 烧脑面试题大赏
【报名】TF54:工程师成长地图与卓越研发组织打造
33 million IOPs, 39 microsecond delay, carbon footprint certification, who is serious?
AtomicIntegerArray源码分析与感悟
[code analysis (5)] communication efficient learning of deep networks from decentralized data
Neuron and neural network
服务器中挖矿病毒了,屮
China creates vast research infrastructure to support ambitious climate goals
Tensorflow & pytorch common error reporting
[VMware] address of VMware Tools
Decimal 格式化小数位/DateTime 转换处理
L2-024 tribe (25 points)
可否把模板的头文件和源文件分开编译
freeCodeCamp----time_ Calculator exercise
9月8日,临去松山湖的前夜
Jenkins construction and use