udacity / cn-wechat-weather

100 stars 64 forks source link

腾讯位置服务API调用错误——thirdScriptError #11

Open Haoxin54 opened 5 years ago

Haoxin54 commented 5 years ago

请问一下我在腾讯位置服务申请了key,同时设置开放了微信小程序和WebServiceAPI服务并添加了“qq.com”白名单,但是在小程序中调用的时候遇到了以下报错,应该如何解决?(我尝试了一下教学视频里的APIKey,也遇到了同样的问题。。) thirdScriptError Cannot read property 'qqmapsdk' of undefined;at api getLocation success callback function TypeError: Cannot read property 'qqmapsdk' of undefined at success (http://127.0.0.1:52166/appservice/pages/index/index.js:119:13) at function.o.(anonymous function) (WAService.js:1:1125059) at vC (WAService.js:1:1085159) at Function.success (WAService.js:1:1086826) at Object.success (WAService.js:1:102993) at r (WAService.js:1:421415) at WAService.js:1:421592 at v (WAService.js:1:421601) at Function. (WAService.js:1:423009) at t.function.setTimeout (http://127.0.0.1:52166/appservice/appservice?t=1567929805880:1111:10471)

h53 commented 5 years ago

我也遇到过这种问题,根据这里的错误提示,您应该检查qqmapsdk属性是否正确声明和定义。

// 引入SDK核心类
const QQMapWX = require('../../libs/qqmap-wx-jssdk.min.js');
Page({
  onLoad() {
    this.qqmapsdk = new QQMapWX({
      key: 'XXXXXXXXXXXXXXXXXXX' //申请的key
    });
    this.getNow();
  },
...
  onTapLocation(){
    wx.getLocation({
      success: res=> {
        console.log(res.latitude,res.longitude)
        this.qqmapsdk.reverseGeocoder({
          location:{
            latitude: res.latitude,
            longitude: res.longitude
          },
          success: res=>{
            let city = res.result.address_component.city
            console.log(city)
          }
        })
      }
    })
  }
})