当前位置:网站首页>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);

 Insert picture description here
(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