本文介绍: 微信使用wx.getLocation

1,小程序管理后台 -「开发」-「开发管理」-「接口设置」” 中完成权限申请;

2,需在 app.json 中声明其需调用的地理位置相关接口

 "permission": {
    "scope.userLocation": {  
      "desc": "你的位置信息将用于小程序地图定位"  
    }  
},
"requiredPrivateInfos": [
  "getLocation",
  "choosePoi",
  "chooseAddress"
],

3,在页面使用
 

  // 获取当前地址信息
  getLocation(){
    console.log("获取当前地址");
    var that = this;  
    wx.getLocation({  
      type: 'wgs84',  
      success: function(res) {  
        console.log("获取当前地址",res);
      }  ,
      fail: function(error) {  
        console.log('获取位置失败', error)  
      } 
    });  
  },

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注