Handle scenario where user denied scope.userLocation, guiding them to enable it again.

function ensureLocationAuth() {
wx.getSetting({
success(res) {
if (!res.authSetting['scope.userLocation']) {
wx.openSetting({
success: (res2) => {
if (!res2.authSetting['scope.userLocation']) {
wx.showModal({
title: 'Reminder',
content: 'Location access is required to use this feature.',
cancelText: 'Later',
confirmText: 'Enable',
success: (mRes) => {
if (mRes.confirm) {
ensureLocationAuth();
} else {
wx.showToast({
title: 'Tap the locate button below to retry later',
icon: 'success',
duration: 3000
});
}
}
});
}
}
});
}
}
});
}

Tips:

  1. Avoid looping if user keeps denying—add backoff logic for production.
  2. Provide a clear UI affordance (e.g. map pin button) to retry authorization.
  3. Cache a sentinel flag after N denials to stop prompting.