WeChat applet Tencent Map SDK Gets the current address implementation analysis

How to get the current address of the user, this is to use the small program positioning function: positioning official document

First step acquisition

Write in JS

微信小程序 腾讯地图SDK 获取当前地址实现解析

There will be such a pop-up window after running the project:

微信小程序 腾讯地图SDK 获取当前地址实现解析

It is because developers need to explain the use of user geographic locations.

Solution:

Adds the Permission property in app.json.

微信小程序 腾讯地图SDK 获取当前地址实现解析 This can get the geographic coordinates of the user.

Second steps to talk about the current positioning transition address information

This function needs to use Tencent Map SDK: Official Document

Official document The step of using SDK is quite detailed, and also puts a variety of links:

The security domain name of step 4 is set in your own applet management background Setting 微信小程序 腾讯地图SDK 获取当前地址实现解析

After the step 4 is completed, the downloaded SDK file is placed in the project.

Introduced to the page JS:

We need to use the ReverseGeocoder () method inside SKD, so we are getting This method is called after the current coordinates: 微信小程序 腾讯地图SDK 获取当前地址实现解析

Converts address coordinates to an address, simply displayed on the page:

微信小程序 腾讯地图SDK 获取当前地址实现解析

微信小程序 腾讯地图SDK 获取当前地址实现解析

微信小程序 腾讯地图SDK 获取当前地址实现解析

Finally posted my JS complete code, write a bit small, if anything If you don’t know much, please add me QQ to discuss: 546529770,Thank you ~~

/ ** introduced the SDK core class * / var qqsdk = require (‘../. ./apis/qqmap-wx-jssdk.min.js ‘) Page ({/ ** * Page initial data * / data: {latitude:’, longitude: ”, positiondata: ”}, / ** * Lifecycle Function – Listening Page Load * / Onload: Function (Options) {var _this = this / ** Instantiated SDK Core Core * / VAR QQMAP = New QQSDK ({Key: ‘3B4BZ-QHNK3-HLX34-Ykuqa- YDHCV-CHFFB ‘// Requirements}); / ** Get the current coordinate * / wx.getlocation ({success = res. latitude var longitude = res.longitude qqmap.reversegeocoder ({Success: Function (RES) {var address = res. {latitude: Latitude, longitude: longitude, positiondata: address}})}}}}}}}})

The above is all the content of this article, I hope to help everyone, I hope everyone supports Tumi Cloud.

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment