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 realize the Map location function of WeChat Mini Programs

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

Share

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

This article mainly explains "how to realize the map positioning function of WeChat Mini Programs". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "WeChat Mini Programs map positioning function how to achieve" it!

The method is as follows

1. First of all, you need to have a way to trigger this click event, the following has been written, very simple two lines of code.

Map point selection

two。 Then it's time for js, where we declare the longitude and dimension that were first loaded in data, and then declare the location of a selected point.

Data: {latitude: 0, / / first loaded dimension longitude: 0, / / first loaded longitude mapName: "", / / location of selected point}

3. This is how to perform the map operation in the moveToLocation event, mainly through the wx.chooseLocation method, and then assign the obtained value to the mapName defined in data above.

MoveToLocation () {let that = this wx.chooseLocation ({success: function (res) {console.log (res.name)) / / assign to mapName that.setData ({mapName: res.name})} in data, / / error message fail: function () {console.log (err);}})}

Js complete code

Page ({data: {latitude: 0, / / first loaded dimension longitude: 0, / / first loaded longitude mapName: ", / / location of selected point}, moveToLocation () {let that = this wx.chooseLocation ({success: function (res) {console.log (res.name)) / / assign to mapName that.setData ({mapName: res.name})} in data, / / error message fail: function () {console.log (err);}})})

4. Finally, we need to add this paragraph to the app.json file:

"permission": {"scope.userLocation": {"desc": "your location information will be used for the effect display of Mini Program location interface"}}

5. Show

At this point, I believe you have a deeper understanding of "how to achieve WeChat Mini Programs map positioning function". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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