WeChat applet to get location information

 

Obtain the user's geographic location information (WeChat applet to obtain latitude and longitude; Tencent map reverse analysis;):

1. Apply for developer key (key) and settings / download WeChat applet JavaScriptSDK

2. Open the authorization and configure the app.json file

{
  "pages": ["pages/index/index"],
  "permission": {
    "scope.userLocation": {
      "desc": "请求获取位置"
    }
  }
}

3. Call the function to request

var QQMapWX = require("../../utils/qqmap-wx-jssdk.js");

onLoad:function(){
    var qqmapsdk = new QQMapWX({
      key: '你的key' // 必填
    });
    //getLocation获取经纬度
    wx.getLocation({
        type: 'gcj02',
        success: function (res) {
          //根据经纬度,腾讯地图逆地址解析
          qqmapsdk.reverseGeocoder({
            location: {
              latitude: res.latitude,
              longitude: res.longitude
            },
            success: function (res) {
              console.log(res);
              var address = res.result.address;
              var recommend = res.result.formatted_addresses.recommend;
              addr = address + recommend;
              console.log(addr);
            }
          })
        },
      })
  }

OK.

 

 

 

 

Published 52 original articles · praised 34 · 10,000+ views

Guess you like

Origin blog.csdn.net/weixin_43789195/article/details/105559835