计算机网络/计算机科学与应用/系统/运维/开发

微信小程序 打开腾讯出行服务

// 获取地理位置权限
    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>


泰山崩于前而色不变,麋鹿兴于左而目不瞬,然后可以制利害,可以待敌。--心术

评论

^