Files
ChowBox/miniapp/app.js

31 lines
716 B
JavaScript
Raw Normal View History

App({
globalData: {
userInfo: null,
location: null,
baseUrl: 'http://localhost:8080'
},
onLaunch() {
// 不在 onLaunch 中直接调定位,等用户操作时再申请,符合新版隐私规范
},
getLocation(callback) {
const that = this;
wx.getLocation({
type: 'gcj02',
success: (res) => {
that.globalData.location = {
latitude: res.latitude,
longitude: res.longitude
};
if (callback) callback(null, that.globalData.location);
},
fail: (err) => {
console.log('定位失败:', err);
// 引导用户手动选择位置或开启定位
if (callback) callback(err);
}
});
}
});