In my spare time, I simply wrote a WeChat mini program ibeacon three-point positioning.
I bought seven or eight small ibeacon devices on Taobao in advance and placed them in the corner of the company. Set the coordinate points of the three ibeacons respectively. According to the distance between each ibeacon and the target object that has been turned on, calculate the coordinate position of the target object in the current area. Applicable to shopping instructions within the area. Of course, you must turn on your phone Bluetooth before entering this area.
The following code:
var app = getApp() Page({ data: { motto: 'Hello World', openBLE:'Open Bluetooth device', startBLEDiscovery:'Initialize Bluetooth device', startBLEDevices:'Targeting', reStartSearchBLE:'Reset Bluetooth', startSearchBLE:'Default empty', userInfo: {}, deviceId: '', searchFlag:true, deviceRSSI:'', deviceName:'', deviceId:[], advertisServiceUUIDs: [], advertisData:[], canvasPointX:'', canvasPointY:'', avatarUrl:'../index/', showPosition:'' }, //Event Handling Function bindViewTap: function() { ({ url: '../logs/logs' }) }, onLoad: function () { var that = this //Calling the application instance method to obtain global data //({ deviceId: }) (function(userInfo){ //Update data ({ userInfo:userInfo }) //Judge compatibility if () { //Open the Bluetooth adapter, if showtoast is not turned on ({ success: function(res){ // success //Get the Bluetooth adapter status of the unit ({ success: function(res){ // success ({ searchFlag:true }) }, fail: function(res) { // fail ({ searchFlag:false }) }, complete: function(res) { // complete } }) }, fail: function(res) { // Fail Is the Bluetooth device turned on? ({title:'Please turn on the Bluetooth device of this unit and scan the code again', duration:10000 }) }, complete: function(res) { // complete } }) } else { // If you want users to experience your applet on the latest version of the client, you can prompt this ({ title: 'hint', content: 'The current WeChat version is too low and the function cannot be used. Please upgrade to the latest WeChat version and try again. ' }) } }) }, startBLEDevices: function(){ var that = this ({ services: [], success: function(res){ //Get the status of the Bluetooth device of this unit // success ({ showPosition:setInterval(,1000) }) }, fail: function(res) { // fail }, complete: function(res) { // complete } }) }, // startBLEDevices: function(){ // var that = this // ({ // showPosition:setInterval(,1000) // }) // }, devicesFunc: function(){ var that = this ({ success: function(res){ // (res); var arrayRSSI = new Array(); var arraydeviceName = new Array(); var arraydeviceId = new Array(); // var arrayUUIDs = new Array(); var arrayadvertisData = new Array(); var pointADistance = ''; var pointBDistance = ''; var pointCDistance = ''; for(var i = 0; i<;i++){ //([i].name); if([i].('craft')==0){ //([i]); ([i].RSSI); ([i].name); arraydeviceId[i]= [i].deviceId; arrayUUIDs[i]= [i].advertisServiceUUIDs[i]; arrayadvertisData[i]= [i].advertisData ; Call calculationrssiFunctions corresponding to distance var iRssi = (arrayRSSI[i]); var power = (iRssi-59)/(10*2.0); var mm = (10, power); (arraydeviceName[i]+"The distance is"+mm+"rice"); Pick01,02,03Each,(2,0),(2,2),(0,2)Fixed coordinate points,Do positioning if([i].('craft01')==0){ var pointARSSi = [i].RSSI ; var iRssi = (pointARSSi); var power = (iRssi-55)/(10*2.0); var pointADistance = (10, power); ("a"+pointADistance); (pointARSSi); } if([i].('craft02')==0){ var pointBRSSi = [i].RSSI; var iRssi = (pointBRSSi); var power = (iRssi-55)/(10*2.0); var pointBDistance = (10, power); ("b"+pointBDistance); (pointBRSSi); } if([i].('craft03')==0){ var pointCRSSi = [i].RSSI; var iRssi = (pointCRSSi); var power = (iRssi-57)/(10*2.0); var pointCDistance = (10, power); ("c"+pointCDistance); (pointCRSSi); } } } // From arrayRSSI, take three ibeacons closest to the anchor point to participate in the positioning if( > 3){ //Sort the signal strength according to arrayRSSI. The farther the distance, the smaller the rssi value is. for(var i = 0 ; i < ; i ++){ for(var j = i+1 ; j< ; j++){ if(arrayRSSI[i]<arrayRSSI[j]){ var select = arrayRSSI[i]; arrayRSSI[i] = arrayRSSI[j]; arrayRSSI[j] = select; } } } //Get the nearest three distances for(var i = 0 ; i < 3; i++){ if(i==0){ var pointARSSi = [i].RSSI ; var iRssi = (pointARSSi); var power = (iRssi-55)/(10*2.0); var pointADistance = (10, power); ("a"+pointADistance); (pointARSSi); } if(i==1){ var pointBRSSi = [i].RSSI; var iRssi = (pointBRSSi); var power = (iRssi-55)/(10*2.0); var pointBDistance = (10, power); ("b"+pointBDistance); (pointBRSSi); } if(i==2){ var pointCRSSi = [i].RSSI; var iRssi = (pointCRSSi); var power = (iRssi-57)/(10*2.0); var pointCDistance = (10, power); ("c"+pointCDistance); (pointCRSSi); } } } //Get x and y of the anchor point if(!pointADistance==''&&!pointBDistance==''&&!pointCDistance==''){ var pointDX='';var pointDY = ''; var p = (pointADistance,2)/(pointBDistance,2)/10; pointDX = 2.5 - p; var m = (pointADistance,2)/(pointCDistance,2)/10; pointDY = 2.5 - m; ('The target location X is'+pointDX); ('The target location Y is'+pointDY); if(pointDX > 0 && pointDY > 0){ ({title:'Welcome to 25th floor craft', duration:4000 }); } ({ canvasPointX:pointDX, canvasPointY:pointDY }) //Create a canvas //Calculate the position of the coordinate point on the specified canvas var context = (); ("#00ff00"); //a,b,c,d,e,f a,b start coordinates, c radius, d,e start and end angles (*30,*30,5,0,2*); (); ({ canvasId: 'firstCanvas', actions: () // Get the drawing action array }) ({title:'X axis:'+pointDX+'Y axis:'+pointDY, duration:5000 }); //Start network request ({ url: '/weixinIbeacon/', data: {}, method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT // header: {}, // Set the requested header success: function(res){ // success }, fail: function(res) { // fail }, complete: function(res) { // complete } }) }else{ ({title:'Searching...', duration:1000 }) Start a network request ({ url: '/weixinIbeacon/', data: {}, method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT // header: {}, // Set the requested header success: function(res){ // success }, fail: function(res) { // fail }, complete: function(res) { // complete } }) } }, fail: function(res) { // fail }, complete: function(res) { // complete } }) } , //Dynamic display createList: function(thisName){ var that = this ({ array:[{deviceDistance:"1"},{deviceDistance:"1"},{deviceDistance:"1"},{deviceDistance:"1"},{deviceDistance:"1"}] }) }, reStartSearchBLE: function(){ var that = this //Clear the local data cache ({ success: function(res){ // success }, fail: function(res) { // fail }, complete: function(res) { // complete } }) (); clearInterval(); (); // (0,0,,); //Disconnect Bluetooth var that = this ({ success: function(res){ // success ('Reset successfully'); //Open the Bluetooth adapter, if showtoast is not turned on ({ success: function(res){ // success //Get the Bluetooth adapter status of the unit ({ success: function(res){ // success }, fail: function(res) { // fail }, complete: function(res) { // complete } }) }, fail: function(res) { }, complete: function(res) { // complete } }) }, fail: function(res) { // fail }, complete: function(res) { // complete } }) } //zheli })
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.