Files
ChowBox/miniapp/utils/location.js
王鹏 802b4ba229 fix: 修复 VoiceController Map.of 兼容性 + ExploreController 参数不匹配
- VoiceController: Map.of() -> Collections.singletonMap() 兼容 Java 8
- ExploreController: 补齐 takeoutService.roll() 缺失的 taste/priceRange/allergies 参数

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-08 20:02:27 +08:00

38 lines
1.0 KiB
JavaScript

const app = getApp();
function getLocation() {
return new Promise((resolve, reject) => {
const cached = app.globalData.location;
if (cached) {
resolve(cached);
return;
}
wx.getLocation({
type: 'gcj02',
success: (res) => {
const loc = { latitude: res.latitude, longitude: res.longitude };
app.globalData.location = loc;
resolve(loc);
},
fail: (err) => {
// 常见错误:未授权、隐私协议未同意
const msg = err.errMsg || '';
if (msg.indexOf('auth deny') >= 0 || msg.indexOf('authorize') >= 0) {
wx.showModal({
title: '需要定位权限',
content: '请在设置中允许小程序获取位置,或点击右上角手动选择位置',
confirmText: '去设置',
success: (res) => {
if (res.confirm) wx.openSetting();
}
});
}
reject(new Error('定位失败'));
}
});
});
}
module.exports = { getLocation };