收藏
回答

云函数调用qqmap-wx-jssdk报错wx is not defined?

在云函数中加入了qqmap-wx-jssdk,为何提示

{"errorCode":1,"errorMessage":"user code exception caught",
"stackTrace":"wx is not defined\nReferenceError: wx is not defined\n    at locationsuccess (/var/user/lib/qqmap-wx-jssdk.js:1016:13)\n    at Object.locationProcess (/var/user/lib/qqmap-wx-jssdk.js:650:13)\n    at QQMapWX.calculateDistance (/var/user/lib/qqmap-wx-jssdk.js:1022:17)\n    at EventHandler.exports.main [as realHandler] (/var/user/index.js:22:14)\n    at \u003canonymous\u003e\n    at process._tickCallback (internal/process/next_tick.js:188:7)"}
// 云函数入口文件
const cloud = require('wx-server-sdk')
const QQMapWX = require('./lib/qqmap-wx-jssdk');
const qqmapsdk  = new QQMapWX({
  key: 'TAABZ-MNUEP-3ULD2-VMNEQ-OHQTE-DAFLE'
});


cloud.init({env: cloud.DYNAMIC_CURRENT_ENV})
const db = cloud.database()
const MAX_LIMIT = 100
// 云函数入口函数
exports.main = async (event, context) => {
  // 计算集合记录总数
  const countResult = await db.collection('shop').get()
  // 添加一个新的属性 距离 dis = 人和商店的距离
  // 获取经纬度数组 从 guessArr 获取
  const disArr = countResult.data.map((v) => {
    return { latitude: v.distance.lat, longitude: v.distance.lng };
  });
   
    // 调用腾讯地图的接口 来计算距离
    qqmapsdk.calculateDistance({
      mode: 'driving',
      from: {
        latitude: 13,
        longitude: 37
      },
      to: disArr,
      success: (result)=> {
        if (result.status == 0) {
          // guessArr 进行处理
          const guessArr = res.data.map((v, i) => {
            const data = result.result.elements[i]
            v.dis = data.distance;
            v.duration = Math.ceil(data.duration/60) 
            return v;
          });
          if(!event.page_index) {
            event.page_index = 1
          }
          if(!event.page_count) {
            event.page_count = 10
          }
          const data = guessArr.splice(event.page_index, event.page_count)
          return(data)
        }
      }
  })
}


回答关注问题邀请回答
收藏
登录 后发表内容
问题标签