当前位置:网站首页>基于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
边栏推荐
- 收藏博客贴
- Logging模块
- Haruki Murakami -- Excerpt from "what do I talk about when I talk about running"
- Android interview theme collection
- 联想产品经理林林:天津当地网络运营商网络故障 ZUI系统后台服务器暂时无法正常工作
- JS force deduction brush question 102 Sequence traversal of binary tree
- websocket
- About note 1
- freeCodeCamp----time_ Calculator exercise
- 项目中遇到的问题(五)操作Excel接口Poi的理解
猜你喜欢

Quartus prime hardware experimental development (de2-115 board) experiment II function adjustable comprehensive timer design

Oracle告警日志alert.log和跟踪trace文件中文乱码显示

try --finally

Kettle--控件解析

linux安装mysql后修改密码

What is the difference between blue-green publishing, rolling publishing and gray publishing?

美联储数字货币最新进展

蓝绿发布、滚动发布、灰度发布,有什么区别?

Strange bug of cnpm

神经元与神经网络
随机推荐
专题测试05·二重积分【李艳芳全程班】
Spark入门基本操作
基础知识学习记录
JDBC入门
[code analysis (1)] communication efficient learning of deep networks from decentralized data
Special test 05 · double integral [Li Yanfang's whole class]
Expression「Func「TSource, object」」 转Expression「Func「TSource, object」」[]
_模_板_
freeCodeCamp----time_ Calculator exercise
初探 Lambda Powertools TypeScript
商家案例 | 运动健康APP用户促活怎么做?做好这几点足矣
Port occupied 1
Oracle alarm log alert Chinese trace and trace files
Choreographer full resolution
FBS(fman build system)打包
Decimal 格式化小数位/DateTime 转换处理
mysql通过binlog文件恢复数据
[code analysis (3)] communication efficient learning of deep networks from decentralized data
程序编译调试学习记录
Nodejs安装及环境配置