Is it true that directly calling wx.openLocation, will not pop up the authorization box? I tried three mobile phones but did not play. Why does the official document say that authorization is needed?

is it true that calling wx.openLocation, directly won"t pop up the authorization box? I tried three phones but didn"t play. Why does the official document say that authorization is needed?


Mini Program seems to have updated some time ago. Now to call similar interfaces, you need to actively invite users to authorize. Mini Program will not take the initiative to pull the authorization. Now, first use wx.getSetting, and then call openLocation when successful.
add a layer of button
< button open-type= "openSetting" bindtap= "onGotSetting" to your map icon. Open the authorization settings page < / button >
and then write

in page.
onGotSetting:function(){
    wx.getSetting({
    success(res) {
        if (!res.authSetting['scope.userLocation']) {
            wx.authorize({
                scope: 'scope.userLocation',
                success() {
                    wx.getLocation({
                      type: 'gcj02', //wx.openLocation
                      success: function(res) {
                            //
                        })
                      }
                    })
                })
            }
        }
    })
}


first use getSetting to check whether the user is authorized. If not, hang the authorization window. Now there is usually a button

.
wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.userLocation']) {
            wx.authorize({
              scope: 'scope.userLocation',
              success(res) {
              }
            })
          }
      }
    })
Menu