Small micro-channel program to get the current location

Obtaining user location, api need to use the following three methods:
 
wx.getSetting (): Gets a list of authorized users of information
wx.openSetting (): invoking client applet settings interface
wx.getLocation (): Gets the user's current location
 
< View bindtap = 'getCurrentLocal' > acquires the current position of the </ View >

 

When the user clicks "to get the current position", we call wx.getSetting () method to obtain user authorization information to determine wx.getSetting () method returns the result of whether to include authorization information geographic location.

'scope.userLocation' field indicates the authorized location, other api authorization, such as access to user information, camera and other authorization fields, you can view the official website, a corresponding document, gray machine direct  , specific code as follows:

 

// Get the current location authorization verification 
  getCurrentLocal () {
    let that = this;
    wx.getSetting({
      success(res) {
        IF (res.authSetting [ 'scope.userLocation'] == to false ) { // If denied authorization is provided to open the page 
          wx.openSetting ({
            success(res) {}
          })
        }   The else { // first authorized, or authorized, related directly call API 
          that.getMyLocation ()
        }
      }
    })
  },
  // Get the current location 
  getMyLocation () {
    let that = this
    wx.getLocation({
      type: 'wgs84',
      success(res) {
        console.log(res)
      }
    })
  },

 

 

Guess you like

Origin www.cnblogs.com/Mrrabbit/p/11776332.html