プログラムibeacon 3点位置決め


空いている時間は簡単にWeChatプログラムibeaconの3点の位置付けを書きました.
事前にタオバオを洗って8,8個のibeaconの小さい設備を買って、会社の隅をします.ibeaconの位置座標点を3つずつ設定し、ibeaconからBluetoothを開いたターゲットまでの距離に基づいて、対象物の現在のエリア内の座標位置を計算します.エリア内のショッピングの指示に適用されます.もちろん、このエリアに入る前に携帯のBluetoothを開けておきます.
次のコード:
var app = getApp() 
Page({
  data: {
    motto: 'Hello World',
    openBLE:'      ',
    startBLEDiscovery:'       ',
    startBLEDevices:'    ',
    reStartSearchBLE:'    ',
    startSearchBLE:'   ',
    userInfo: {},
    deviceId: '',
    searchFlag:true,
    deviceRSSI:'',
    deviceName:'',
    deviceId:[],
    advertisServiceUUIDs: [],
    advertisData:[],
    canvasPointX:'',
    canvasPointY:'',
    avatarUrl:'../index/bg-image.jpg',
    showPosition:'' 
  },
  //      
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () { 
    var that = this
    //                
    //that.setData({ deviceId: opt.deviceId })  
    app.getUserInfo(function(userInfo){
      //     
      that.setData({
        userInfo:userInfo
      })
      //     
      if (wx.openBluetoothAdapter) { 
      //       ,       showtoast
      wx.openBluetoothAdapter({
        success: function(res){
          // success
          //            
          wx.getBluetoothAdapterState({
            success: function(res){
              // success
              that.setData({
                searchFlag:true
              }) 
            },
            fail: function(res) {
              // fail 
              that.setData({
                searchFlag:false
              })
            },
            complete: function(res) {
              // complete
            }
          })
        },
        fail: function(res) {
          // fail             
           wx.showToast({title:'         ,    ', duration:10000  })
        },
        complete: function(res) {
          // complete
        }
      })
      } else {
          //                        ,       
          wx.showModal({
            title: '  ',
            content: '        ,       ,             。'
          })
        }  
       
   })
   }, 

   startBLEDevices: function(){
       var that = this  
         wx.startBluetoothDevicesDiscovery({
            services: [],
            success: function(res){ 
              //             
                  // success  
              that.setData({
                showPosition:setInterval(that.devicesFunc,1000)
              })    
            },
            fail: function(res) {
            // fail 
          },
          complete: function(res) {
            // complete 
          }
       })
   },
  //  startBLEDevices: function(){
  //    var that = this
  //    that.setData({
  //      showPosition:setInterval(that.devicesFunc,1000)
  //    }) 
  //  },
   devicesFunc: function(){
       var that = this 
       
        wx.getBluetoothDevices({
          success: function(res){
           // console.log(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 3){
               //  arrayRSSI        .    rssi   
                for(var i = 0 ; i < arrayRSSI.length ; i ++){
                  for(var j = i+1 ; j< arrayRSSI.length ; j++){
                    if(arrayRSSI[i] 0 && pointDY > 0){ 
                  wx.showToast({title:'    25 craft', duration:4000  }); 
                 }
                that.setData({
                   canvasPointX:pointDX,
                   canvasPointY:pointDY
                 })
                
                //     
                //        canvas      
                var context = wx.createCanvasContext(); 
                context.setStrokeStyle("#00ff00");
                //a,b,c,d,e,f   a,b    ,c  ,d,e        
                context.arc(that.data.canvasPointX*30,that.data.canvasPointY*30,5,0,2*Math.PI);
                context.fill();
                wx.drawCanvas({
                  canvasId: 'firstCanvas',
                  actions: context.getActions() //         
                }) 

                wx.showModal({title:'X :'+pointDX+'Y :'+pointDY, duration:5000  }); 
                 //      
                 wx.request({
                   url: 'http://craftww.cn/weixinIbeacon/index.php',
                   data: {},
                   method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
                   // header: {}, //       header
                   success: function(res){
                     // success
                   },
                   fail: function(res) {
                     // fail
                   },
                   complete: function(res) {
                     // complete
                   }
                 })

               }else{
                wx.showToast({title:'    ...', duration:1000  })
                       
                 wx.request({
                   url: 'http://craftww.cn/weixinIbeacon/index.php',
                   data: {},
                   method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
                   // header: {}, //       header
                   success: function(res){
                     // success
                   },
                   fail: function(res) {
                     // fail
                   },
                   complete: function(res) {
                     // complete
                   }
                 })
               } 
  
          },
          fail: function(res) {
            // fail
          },
          complete: function(res) {
            // complete
          }
        }) 
   } ,
   //    
   createList: function(thisName){
     var that = this 
          that.setData({
            array:[{deviceDistance:"1"},{deviceDistance:"1"},{deviceDistance:"1"},{deviceDistance:"1"},{deviceDistance:"1"}]
          }) 
   },
   reStartSearchBLE: function(){ 
     var that = this
    //        
    wx.stopBluetoothDevicesDiscovery({
      success: function(res){
        // success
      },
      fail: function(res) {
        // fail
      },
      complete: function(res) {
        // complete
      }
    })
     wx.clearStorageSync();
     clearInterval(that.data.showPosition); 
     console.log(that.data.showPosition);
    // that.context.clearRect(0,0,canvas.width,canvas.height);
     //    
     var that = this
     wx.closeBluetoothAdapter({
       success: function(res){
         // success
         console.log('    ');
          //       ,       showtoast
      wx.openBluetoothAdapter({
        success: function(res){
          // success
          //            
          wx.getBluetoothAdapterState({
            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
})