当前位置:网站首页>Three point positioning based on ibeacons (wechat applet)
Three point positioning based on ibeacons (wechat applet)
2022-04-23 14:04:00 【one billion twenty-nine million one hundred and seventy-nine th】
This article shares three core positioning codes , And the problems found in the process of writing
1: Three point positioning , No, there are three ibeacons You can connect them all , stay wx.getBeacons({}) You will find it easy and difficult to get three , So do the test and buy more ibeacons
2: The Pythagorean theorem is used to locate almost three points on the Internet , Therefore, calculating the distance from moving point to fixed point has become the key , Yes 2 Methods
(1) Here I use the official distance , The applet interface itself will return the distance , This should also be considered rssi Fluctuations and attenuation .
(2) There are also calculation formulas ( I feel that the accuracy is not as high as that given by wechat officials )
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) Some code is also copied , Self improvement , Simplified code , The last part is to calculate x,y I don't understand the code of coordinates , So the final result is wrong . The following code has not been understood yet How to calculate the coordinates of . take 01,02,03 Respectively ,(2,0),(2,2),(0,2) Fixed coordinate point , Positioning
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 Code You can calculate the result But the error is big
predict:function(){
var that=this
wx.startBeaconDiscovery({
// Set up ibeacons Parameters of
uuids: ['uuid'],
// Successful connection
success: function () {
console.log(" Start scanning devices ")
// monitor iBeacon Update event of the device
wx.onBeaconUpdate(function (res) {
// Get and connect Bluetooth devices
wx.getBeacons({
success: (result) => {
console.log("ibacon The number of "+res.beacons.length)
//rssi Strength
var arrayRSSI = new Array();
// distance
var arrayaccay = new Array();
//major
var arraymajor = new Array();
// The distance from the three fixed points to the moving point
var pointADistance = '';
var pointBDistance = '';
var pointCDistance = '';
for(var i = 0; i<res.beacons.length;i++){
// Put the distance and intensity into the array 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){
// Distance ordering
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;
}
}
}
}
// Assign three values to
for(var i = 0 ; i < 3; i++){
if(i==0){
pointADistance=arrayaccay[i]
console.log("a distance :"+pointADistance);
}
if(i==1){
pointBDistance=arrayaccay[i]
console.log("b distance :"+pointBDistance);
}
if(i==2){
pointCDistance=arrayaccay[i]
console.log("c distance :"+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(' Target location X yes '+top);
console.log(' Target location Y yes '+left);
that.setData({
left:left,
top:top
})
}
},
})
})
},
fail:function(){
wx.showToast({
title: ' Not in the range of equipment ',
icon: 'fail',
duration: 500
})
}
}),
// The search timeout Stop scanning the device
setTimeout(function () {
wx.stopBeaconDiscovery({
success: function () {
console.log(" Stop scanning the device !");
}
});
}, 10000);
},
I hope you can help solve the problem , Or there is a better solution to leave a message or send a private message to me .
版权声明
本文为[one billion twenty-nine million one hundred and seventy-nine th]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231401298017.html
边栏推荐
- L2-024 tribe (25 points)
- PyMySQL
- 生产环境——
- Intégration de Clusters CDH Phoenix basée sur la gestion cm
- 读了一篇博客,重新理解闭包整理一下
- What is the difference between blue-green publishing, rolling publishing and gray publishing?
- log4j 输出日志信息到文件中
- 蓝绿发布、滚动发布、灰度发布,有什么区别?
- CDH cluster integration Phoenix based on CM management
- DDT+Excel进行接口测试
猜你喜欢
Quartus Prime硬件实验开发(DE2-115板)实验一CPU指令运算器设计
What is the difference between blue-green publishing, rolling publishing and gray publishing?
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
Taobao released the baby prompt "your consumer protection deposit is insufficient, and the expiration protection has been started"
There is a mining virus in the server
go 语言 数组,字符串,切片
Wechat applet
基於CM管理的CDH集群集成Phoenix
记录一个奇怪的bug:缓存组件跳转之后出现组件复制
JMeter pressure test tool
随机推荐
BUG_me
Analysis and understanding of atomicintegerarray source code
分页SQL
DDT+Excel进行接口测试
腾讯根据ip解析地址
linux安装mysql后修改密码
Introduction to spark basic operation
Yarn online dynamic resource tuning
Quartus prime hardware experimental development (de2-115 board) experiment II function adjustable comprehensive timer design
专题测试05·二重积分【李艳芳全程班】
jacob打印word
微信小程序与低功耗蓝牙通信-接受硬件端发送来的数据(四)
VsCode-Go
收藏博客贴
JS 烧脑面试题大赏
Strange bug of cnpm
JS 力扣刷题 103. 二叉树的锯齿形层序遍历
Intégration de Clusters CDH Phoenix basée sur la gestion cm
freeCodeCamp----arithmetic_ Arranger exercise
linux MySQL数据定时dump