Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use WeChat Mini Programs's continuous positioning function in the background

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "How to use the background continuous positioning function of Weixin Mini Programs." The editor shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "How to use the background continuous positioning function of Weixin Mini Programs" can help you solve the problem.

The Weixin Mini Programs team updated the base library 2.8.0 on July 30

Mini programs background continuous positioning function and contact positioning interface are newly added

From top to bottom,

1.wx.onLocationChange//monitor real-time location change

2.wx.stopLocationUpdate//close monitoring real-time position changes, front and rear stations stop receiving messages

3.wx.startLocationUpdate//Open Mini programs to receive location messages when they enter the foreground

4.wx.startLocationUpdataBackground//Start Mini programs to receive location messages when entering the front and background

Details can be found at developers.weixin.qq.com/miniprogram/dev/api/location/wx.startLocationUpdateBackground.html

Just do the project needs to use the background positioning, the following describes the use of the method:

To achieve background persistent positioning, you need to use the above 1, 2, 4

1. First, you need to add it to app.josn, so that Mini programs can invoke the positioning function in the background

"requiredBackgroundModes": [ "location"],

2. Add the api we need to the index.js page

First of all, we need to open Mini programs to receive location messages when entering the front and back

wx.startLocationUpdateBackground({ success(res) { console.log ('open background location', res) }, fail(res) { console.log ('Failed to open background location', res) } })

Note that this API cannot be debugged on developer tools, only on real machines

After calling this method successfully, we can use wx.onLocationChange to get the real-time location change

wx.onLocationChange(function(res) { console.log('location change', res) })

The following figure shows the real-time positioning information obtained from the debugging of the real machine

New location information is acquired about once every 3 seconds. After Mini programs enter the background, the status bar will display that Mini programs are using location information, as shown in the following figure

How to close requires calling the wx.stopLocationUpdate method

After testing, after calling wx.stopLocationUpdate to stop listening for real-time location changes

wx.onLocationChange continues to function without being called again after wx. startLocationUpdateaBackground is called again

About "Weixin Mini Programs (Mini) background continuous positioning function how to use" content introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report