当前位置:网站首页>Indoor and outdoor map switching (indoor three-point positioning based on ibeacons)
Indoor and outdoor map switching (indoor three-point positioning based on ibeacons)
2022-04-23 14:04:00 【one billion twenty-nine million one hundred and seventy-nine th】
The program is implemented in wechat applet
1: Generalization
Tencent maps use api:apihttps://lbs.qq.com/miniProgram/jsSdk/jsSdkGuide/jsSdkOverview
The key is , Request key , Use... In applets .
2: Outdoor map
When you enter the indoor map , Remind you whether to switch to indoor map
wxml
<map
id="map"
longitude="{
{longitude}}"
latitude='{
{latitude}}'
scale='18'
show-location
markers='{
{markers}}'
subkey=" I applied for key"
style="height: {
{height}}px;">
</map>
<view class="button-position"></view>
js
Page({
data: {
height: 0,
longitude: 0,
latitude: 0,
markers: [],
posTimer: null,
timeGap: 10000
},
onLoad: function (options) {
const _this = this;
// Get the system height , Set map size
wx.getSystemInfo({
success: function (res) {
_this.setData({
height: res.windowHeight
})
},
});
// Get the current location
wx.getLocation({
type: 'gcj02',
success(res) {
_this.setData({
longitude: res.longitude,
latitude: res.latitude
})
console.log(res.longitude+"jjj"+res.latitude)
}
});
// Read the configuration file in the cache
wx.getStorage({
key: 'config',
success(res) {
const data = res.data;
_this.setData({
outdoorTimeGap: Number(data.outdoorTimeGap) * 1000
});
},
fail(res) {
console.warn(' Configuration file read failed !');
}
});
},
/**
* Life cycle function -- Monitor page display
*/
onShow: function () {
let isGoIndoor = true,
_this = this;
const timer = setInterval(function () {
wx.getLocation({
type: 'gcj02',
success: function (res) {
if(res.longitude>105 && res.longitude<115 && res.latitude>35 && res.latitude<45){
wx.showModal({
title: ' Tips ',
content: ' It is detected that you are approaching the room , Do you want to switch to indoor map ',
confirmText: ' Get into ',
cancelText: ' Cancel ',
success(resp) {
if (resp.confirm) {
wx.navigateTo({
url: '/pages/indoor/indoor',
})
}
}
});
}
},
})
}, _this.data.timeGap);
this.setData({
posTimer: timer
});
},
/**
* Life cycle function -- Monitor page hidden
*/
onHide: function () {
clearInterval(this.data.posTimer);
this.setData({
posTimer: null
});
}
})
wxcss
.main-body {
position: relative;
}
.pos-img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
.point {
position: absolute;
width: 50rpx;
height: 50rpx;
border-radius: 25rpx;
text-align: center;
line-height: 50rpx;
color: #fff;
background-color: #f00;
}
.function-tab {
display: flex;
flex-direction: row;
position: absolute;
bottom: 0%;
width: 100%;
height: 120rpx;
background-color: #fff;
box-shadow: 0 0 5px 3px rgba(0, 0, 0, 0.5);
}
.function-tab .tab-item {
width: 100%;
height: 100%;
line-height: 120rpx;
text-align: center;
}
.function-tab .tab-item image {
position: relative;
width: 48rpx;
height: 48rpx;
top: 10rpx;
margin-right: 20rpx;
}
.function-tab .tab-item navigator {
display: inline-block;
}
.mark {
position: absolute;
z-index: 1000;
width: 48rpx;
height: 64rpx;
}

2: Indoor map use and three-point positioning
effect

predict:function(){
var that=this
wx.startBeaconDiscovery({
// Set up ibeacons Parameters of
uuids: ['E2C56DB5-DFFB-48D2-B060-D0F5A71096E0'],
// Successful connection
success: function () {
console.log(" Start scanning devices ")
// monitor iBeacon Update event of the device
wx.onBeaconUpdate(function (res) {
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
arrayRSSI.push(Math.abs(res.beacons[i].RSSI));
arrayaccay.push(res.beacons[i].accuracy)
arraymajor.push(res.beacons[i].major)
}
// // take 2 Merge arrays into 1 individual
// var activeSubjectsArr = [];
// for (var i = 0; i < arraymajor.length; i++) {
// var activeSubjectsObject = {};
// for (var j = 0; j < arrayaccay.length; j++) {
// if (i == j) {
// activeSubjectsObject.name = arraymajor[i];
// activeSubjectsObject.value = arrayaccay[j];
// activeSubjectsArr.push(activeSubjectsObject);
// }
// }
// }
// console.log(activeSubjectsArr[0].name);
// from arrayRSSI Take three points closest to the positioning point ibeacon Participate in positioning
if(arrayaccay.length > 3 || arrayaccay.length==3){
// according to arrayRSSI Sort the signal strength . The farther the distance rssi The smaller the value.
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;
}
}
}
}
// Get the three closest distances
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
})
}
},
})
// console.log(" The equipment uuid yes :"+res.beacons[0].uuid)
// console.log(" distance ibeacons The distance is :"+res.beacons[0].accuracy)
// console.log(" distance ibeacons The signal strength is :"+res.beacons[0].rssi)
// console.log(" distance ibeacons The signal strength is :"+res.beacons[0].major)
// var distance=res.beacons[0].accuracy
// var major=res.beacons[0].major
// var rssi=-res.beacons[0].rssi
})
},
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);
},
版权声明
本文为[one billion twenty-nine million one hundred and seventy-nine th]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231401298058.html
边栏推荐
- JS 力扣刷题 102. 二叉树的层序遍历
- Interesting talk about network protocol
- Choreographer full resolution
- SPC简介
- Wechat applet
- go 语言 数组,字符串,切片
- POI operation word template replaces data and exports word
- What is the difference between blue-green publishing, rolling publishing and gray publishing?
- Oracle alarm log alert Chinese trace and trace files
- 蓝绿发布、滚动发布、灰度发布,有什么区别?
猜你喜欢

CentOS mysql多实例部署

DeepinV20安装Mariadb

Program compilation and debugging learning record

趣谈网络协议

Quartus Prime硬件实验开发(DE2-115板)实验二功能可调综合计时器设计

STM32学习记录0007——新建工程(基于寄存器版)

As a junior college student, I studied hard in closed doors for 56 days, won Ali offer with tears, five rounds of interviews and six hours of soul torture

专题测试05·二重积分【李艳芳全程班】

JS brain burning interview question reward

Qt Designer怎样加入资源文件
随机推荐
基础知识学习记录
freeCodeCamp----arithmetic_ Arranger exercise
switch使用(微信小程序)
读了一篇博客,重新理解闭包整理一下
室内外地图切换(室内基于ibeacons三点定位)
nodejs通过require读取本地json文件出现Unexpected token / in JSON at position
Kettle -- control parsing
AtomicIntegerArray源码分析与感悟
Yarn online dynamic resource tuning
Android篇:2019初中级Android开发社招面试解答(中
封装logging模块
使用Postman进行Mock测试
STM32学习记录0007——新建工程(基于寄存器版)
BUG_me
mysql新表,自增id长达20位,原因竟是......
33 million IOPs, 39 microsecond delay, carbon footprint certification, who is serious?
生产环境——
DDT+Excel进行接口测试
linux MySQL数据定时dump
多重继承虚基类习题