当前位置:网站首页>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
边栏推荐
- 快捷键(多行)
- 变长参数__VA_ARGS__ 和 写日志的宏定义
- Neuron and neural network
- JS force deduction brush question 103 Zigzag sequence traversal of binary tree
- 初识go语言
- Windos中安装labellmg教程
- 微信小程序与低功耗蓝牙通信-接受硬件端发送来的数据(四)
- Wechat applet
- Taobao released the baby prompt "your consumer protection deposit is insufficient, and the expiration protection has been started"
- freeCodeCamp----time_ Calculator exercise
猜你喜欢
浅谈基于openssl的多级证书,Multi-level CA的签发和管理,以及双向认证
微信小程序获取登录用户信息、openid和access_token
Nacos+AspnetCore+Ocelot实战编码
Quartus Prime硬件实验开发(DE2-115板)实验二功能可调综合计时器设计
微信小程序调用客服接口
Crontab timing task output generates a large number of mail and runs out of file system inode problem processing
Ptorch classical convolutional neural network lenet
专题测试05·二重积分【李艳芳全程班】
Windos中安装labellmg教程
Quartus Prime硬件实验开发(DE2-115板)实验一CPU指令运算器设计
随机推荐
Universal template for scikit learn model construction
容差分析相关的计算公式
freeCodeCamp----arithmetic_ Arranger exercise
linux MySQL数据定时dump
linux安装mysql后修改密码
Oracle alarm log alert Chinese trace and trace files
接口文档yaml
Decimal 格式化小数位/DateTime 转换处理
微信小程序与低功耗蓝牙通信-往硬件端发送数据(三)
JS 烧脑面试题大赏
网站_收藏
Node接入支付宝开放平台的沙箱实现支付功能
jacob打印word
基于ibeacons签到系统
Wechat applet
CentOS mysql多实例部署
Android: answers to the recruitment and interview of intermediate Android Development Agency in early 2019 (medium)
多线程 @Async 线程池
烟雾传感器(mq-2)使用详细教程(基于树莓派3b+实现)
蓝绿发布、滚动发布、灰度发布,有什么区别?