当前位置:网站首页>Wechat applet obtains the current location (startlocationupdate, onlocationchange, offlocationchange)
Wechat applet obtains the current location (startlocationupdate, onlocationchange, offlocationchange)
2022-06-13 02:52:00 【Programming Bruce Lee】
Wechat applet gets the current location
problem
I've been using it wx.getLocation() Method to get the user's location , Discovery is always a matter of chance , Our call frequency is once per second , When doing other business, it will also call , Refer to official documents and find Location document This approach is limited , Wechat restrictions 30 Only one success per second , Other returns fail .
resolvent
Use startLocationUpdate、onLocationChange、offLocationChange Use the three methods together , It can obtain the user's location in real time , And frequent calls do not fail .
Wrapper utility class
// Underground information location acquisition tool class
/** * Get the current location of the user 【 Adapt to the new version of wechat to obtain the location information in the field , used getLocation Frequent method calls have performance problems , also 30 You can only succeed once per second 】 */
const getLocation = () => {
return new Promise((resolve, reject) => {
let _locationChangeFn = (res) => {
resolve(res) // Send back the location information in the field
wx.offLocationChange(_locationChangeFn) // Turn off real-time positioning
wx.stopLocationUpdate(_locationChangeFn); // lsnrctl stop If you don't turn off listening , Sometimes it's very slow to get the location
}
wx.startLocationUpdate({
success: (res) => {
wx.onLocationChange(_locationChangeFn)
},
fail: (err) => {
// Regain location permissions
wx.openSetting({
success(res) {
res.authSetting = {
"scope.userLocation": true
}
}
})
reject(err)
}
})
})
}
module.exports = {
getLocation
}
call
const locationUtils = require('../../../utils/location') // Introduce tool classes
// Get current location
locationUtils.getLocation().then(res => {
console.log(' The latitude and longitude of the current position is :')
console.log(res.latitude,res.longitude)
})
边栏推荐
- Ijkplayer source code - audio playback
- Opencv 08 demonstrates the effect of opening and closing operations of erode, dilate and morphological function morphologyex.
- Entity framework extends the actual combat, small project reconfiguration, no trouble
- How to manage the IT R & D department?
- 数仓笔记|针对客户维度建模需要关注的5个因素
- Rough understanding of wechat cloud development
- House raiding
- Linked list: reverse linked list
- Simple use of leaflet - offline map scheme
- [reading papers] deep learning face representation by joint identification verification, deep learning applied to optimization problems, deepid2
猜你喜欢

Why does it feel that most papers still use RESNET as the backbone network rather than densenet?
![[reading papers] comparison of deeplobv1-v3 series, brief review](/img/80/714b8e5b2ad31b0a1a0b8320a3c714.jpg)
[reading papers] comparison of deeplobv1-v3 series, brief review

Node uses post to request req Pit with empty body

Radio design and implementation in IVI system

Use of OpenCV 12 findcircuits and drawcircuits
![HEAP[xxx.exe]: Invalid address specified to RtlValidateHeap( 0xxxxxx, 0x000xx)](/img/c9/884aa008a185a471dfe252c0756fc1.png)
HEAP[xxx.exe]: Invalid address specified to RtlValidateHeap( 0xxxxxx, 0x000xx)

Bi modal progressive mask attention for fine graded recognition

03 recognize the first view component

Introduction and download of common data sets for in-depth learning (with network disk link)
![[data analysis and visualization] key points of data drawing 4- problems of pie chart](/img/e1/618ff53b33b4b1de6acf4942130c17.jpg)
[data analysis and visualization] key points of data drawing 4- problems of pie chart
随机推荐
二叉树初始化代码
MySQL index
Change tax for 2
Ijkplayer source code -- Library loading and initialization
[data analysis and visualization] key points of data drawing 12- importance of chart notes
Implementing fillet in custom dialog
Summary of innovative ideas of transformer model in CV
数仓笔记|针对客户维度建模需要关注的5个因素
[reading point paper] yolo9000:better, faster, stronger, (yolov2), integrating various methods to improve the idea of map and wordtree data fusion
Digital IC Design -- FIFO design
Stm32f4 DMA Da sine wave generator keil5 Hal library cubemx
Stack: daily temperature
IOS interview · full bat interview record of an IOS programmer (including the true interview questions of Baidu + Netease + Alibaba)
[data analysis and visualization] key points of data drawing 10- construction of legend
Ijkplayer source code -- mnatemediaplayer of ijkmediaplayer
Why does it feel that most papers still use RESNET as the backbone network rather than densenet?
Ijkplayer source code ---setdatasource
js 解构赋值
Rough understanding of wechat cloud development
Collection of IOS development interview and underlying learning videos