How to use ibeacon to realize three-point positioning in WeChat Mini Programs
Most people do not understand the knowledge points of this article "how to use ibeacon to achieve three-point positioning in WeChat Mini Programs", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use ibeacon to achieve three-point positioning in WeChat Mini Programs" article.
The code is as follows:
Var app = getApp () Page ({data: {motto: 'Hello World', openBLE:' turn on Bluetooth device', startBLEDiscovery:' initialize Bluetooth device', startBLEDevices:' destination location', reStartSearchBLE:' reset Bluetooth', startSearchBLE:' default null', userInfo: {}, deviceId:', searchFlag:true, deviceRSSI:'', deviceName:'', deviceId: [], advertisServiceUUIDs: [], advertisData: [], canvasPointX:'' CanvasPointY:'', avatarUrl:'../index/bg-image.jpg', showPosition:''}, / / event handler function bindViewTap: function () {wx.navigateTo ({url:'.. / logs/logs'})} OnLoad: function () {var that = this / / call the method of the application instance to obtain global data / / that.setData ({deviceId: opt.deviceId}) app.getUserInfo (function (userInfo) {/ / update data that.setData ({userInfo:userInfo}) / / determine compatibility if (wx.openBluetoothAdapter) {/ / Open Bluetooth adapter If you do not open showtoast wx.openBluetoothAdapter ({success: function (res) {/ / success / / get the Bluetooth adapter status 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 whether the Bluetooth device wx.showToast has been turned on ({title:', please open the local Bluetooth device Re-scan the code', duration:10000})}, complete: function (res) {/ / complete}})} else {/ / if you want users to experience your Mini Program on the latest version of the client, you can prompt wx.showModal ({title: 'hint', content: 'the current Wechat version is too low to use this feature Please upgrade to the latest Wechat version and try again.' })})}, startBLEDevices: function () {var that = this wx.startBluetoothDevicesDiscovery ({services: [], success: function (res) {/ / get native Bluetooth device status / / 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) {/ / sort the signals according to arrayRSSI. The farther the distance, the smaller the rssi value 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:' Welcome to the 25th floor craft', duration:4000});} that.setData ({canvasPointX:pointDX, canvasPointY:pointDY}) / / create canvas / / calculate the location of the coordinate points on the specified canvas display var context = wx.createCanvasContext (); context.setStrokeStyle ("# 00ff00") / / the starting coordinates, c radius, starting and ending angles of context.arc (that.data.canvasPointX*30,that.data.canvasPointY*30,5,0,2*Math.PI); context.fill () Wx.drawCanvas ({canvasId: 'firstCanvas', actions: context.getActions () / / get drawing action array}) wx.showModal ({title:' X axis:' + pointDX+' Y axis:'+ pointDY, duration:5000}) / / start network request wx.request ({url: 'http://craftww.cn/weixinIbeacon/index.php', 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 {wx.showToast ({title:' is searching.' Duration:1000}) start network request wx.request ({url: 'http://craftww.cn/weixinIbeacon/index.php', 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 that.setData ({array: [{deviceDistance: "1"}, {deviceDistance: "1"}]})} ReStartSearchBLE: function () {var that = this / / clear the local data cache 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; / disconnect Bluetooth var that = this wx.closeBluetoothAdapter ({success: function (res) {/ / success console.log ('reset successful') / / turn on the Bluetooth adapter If showtoast wx.openBluetoothAdapter is not opened ({success: function (res) {/ / success / / get the Bluetooth adapter status 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}) these are the contents of the article "how to use ibeacon to achieve three-point positioning in WeChat Mini Programs" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.