微信小程序通過經緯度獲取詳細地址


微信小程序正常通過getLocation只能獲取到當前用戶的經緯度信息,想要獲取詳細信息需要通過微信小程序JavaScript SDK反編譯獲取詳細地址

准備條件:

1配置騰訊地圖秘鑰,並且開啟webserviceAPI服務,不要往白名單里添加東西

2小程序引入微信小程序JavaScriptSDK

3小程序合法域名添加https://apis.map.qq.com,否則真機無法顯示

騰訊地圖服務網址http://lbs.qq.com/miniProgram/jsSdk/jsSdkGuide/jsSdkOverview

然后就可以了

小程序調用

var QQMapWX = require('../new-order-submit/address/qqmap-wx-jssdk.js');
var qqmapsdk;
Page({
 data:{
 
} ,
onLoad{
 // 實例化API核心類
    qqmapsdk = new QQMapWX({
      key: 你的key'
    });
},
shouquanweizhi:function(){
    var that = this
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        console.log(res)
        var latitude = res.latitude;
        var longitude = res.longitude;
        qqmapsdk.reverseGeocoder({
          location: {
            latitude: latitude,
            longitude: longitude
          },
          success: function (res) {
            // console.log(JSON.stringify(res));
            let province = res.result.ad_info.province
            let city = res.result.ad_info.city
            that.setData({
              province:province
            })
          },
          fail: function (res) { console.log(res); },
          complete: function (res) { }
        });
        wx.login({ });
      },
      fail: function (res) {
        //未開啟定位權限,拉起授權
        if (res.errMsg == 'getLocation:fail auth deny') {
          //重新拉起授權
          wx.openSetting({
            success: function (res) {
              console.log(res)
              if (res.authSetting['scope.userLocation'] == false) {
                wx.showModal({
                  title: '提示',
                  content: '您未開啟定位權限,將導致無法使用本軟件',
                  showCancel: false
                });
              } else {
                wx.showModal({
                  title: '提示',
                  content: '您已開啟定位權限,請重新點擊登錄',
                  showCancel: false
                });
              }
            }
          });
        }
      }
    })
  }
 
})


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM