当前位置:网站首页>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
边栏推荐
猜你喜欢

Kettle -- control parsing

DeepinV20安装Mariadb

Record a strange bug: component copy after cache component jump

33 million IOPs, 39 microsecond delay, carbon footprint certification, who is serious?

趣谈网络协议

微信小程序进行蓝牙初始化、搜索附近蓝牙设备及连接指定蓝牙(一)

Interesting talk about network protocol

Nacos+AspnetCore+Ocelot实战编码

Programming travel function

Qt Designer怎样加入资源文件
随机推荐
L2-024 tribe (25 points)
There is a mining virus in the server
Programming travel function
9月8日,临去松山湖的前夜
理解虚基类、虚函数与纯虚函数的概念(转)
scikit-learn构建模型的万能模板
PyMySQL
Intégration de Clusters CDH Phoenix basée sur la gestion cm
Nifi 快速安装及文件同步操作
SPC简介
分页SQL
PATH环境变量
Taobao released the baby prompt "your consumer protection deposit is insufficient, and the expiration protection has been started"
程序编译调试学习记录
接口文档yaml
Haruki Murakami -- Excerpt from "what do I talk about when I talk about running"
Android: answers to the recruitment and interview of intermediate Android Development Agency in early 2019 (medium)
联想产品经理林林:天津当地网络运营商网络故障 ZUI系统后台服务器暂时无法正常工作
对List集合进行分页
leetcode--357. Count the number of different figures