// 获取地理位置权限 wx.getLocation({ type: 'gcj02', success: (res) => { const latitude = res.latitude; const longitude = res.longitude; // 可逆地理编码获取具体地址(需调用第三方API或微信接口) this.setData({ address: `${latitude},${longitude}` }); }, fail: () => { wx.showToast({ title: '获取位置失败', icon: 'none' }); } });
// 按钮点击事件处理函数 handleTapButton() { console.log(444) if (!this.data.address) { wx.showToast({ title: '请先获取地址', icon: 'none' }); return; } wx.navigateToMiniProgram({ appId: 'wx65cc950f42e8fff1', path: "/pages/index/index?sourceAddress=${encodeURIComponent(this.data.address)}`", success: (res) => { console.log('跳转成功'); }, fail: (err) => { console.error('跳转失败:', err); wx.showToast({ title: '无法打开出行服务', icon: 'none' }); } }); },
"navigateToMiniProgramAppIdList": ["wx65cc950f42e8fff1"]
<button type="primary" bindtap="handleTapButton">打车</button>