//index.js
//获取应用实例
Page({
  data: { location: {}
 },

  onLoad: function () {
    var that = this
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        that.setData({
          location: {
            longitude: res.longitude,
            latitude: res.latitude
          }
        })
      }
    })
    //判断是否获得了用户地理位置授权
    wx.getSetting({
      success: (res) => {
        if (!res.authSetting['scope.userLocation'])
          that.openConfirm()
      }
    })
  },

  openConfirm: function () {
    wx.showModal({
      content: '检测到您没打开美团外卖的定位权限,是否去设置打开?',
      confirmText: "确认",
      cancelText: "取消",
      success: function (res) {
        console.log(res);
        //点击“确认”时打开设置页面
        if (res.confirm) {
          console.log('用户点击确认')
          wx.openSetting({
            success: (res) => { }
          })
        } else {
          console.log('用户点击取消')
        }
      }
    });
  },
})