- 当前 Bug 的表现(可附上截图)
微信小程序上线之后地图插件api无法使用,在开发状态下工具里和真机调试都是正常使用的。不知道是不是哪里没有配置好。
报错信息:undefined is not an object (evaluating 't.result.location');at api request complete callback function complete@https://pages/job/job.js:239:19complete@https://utils/qqmap-wx-jssdk.js:611:27complete@https://lib/WASubContext.js:1:997537https://lib/WASubContext.js:1:379138https://lib/WAService.js:1:102577E@https://lib/WASubContext.js:1:363793https://lib/WASubContext.js:1:645173emit@https://lib/WASubContext.js:1:382017Ka@https://lib/WASubContext.js:1:645650https://lib/WASubContext.js:1:646867https://lib/WASubContext.js:1:392277https://lib/WAService.js:1:118852m@https://lib/WAService.js:1:1827
- 预期表现
- 复现路径
- 提供一个最简复现 Demo
import { $wuxGallery } from '../../dist/index' import { $wuxCalendar } from '../../dist/index' import { $wuxDialog } from '../../dist/index' let req = require( '../../utils/request.js' ); let api = require( '../../utils/api.js' ); const util = require( '../../utils/util.js' ); var QQMapWX = require( '../../utils/qqmap-wx-jssdk.js' ); var qqmapsdk; Page({ data: { urls: [], dataList: [], date:[], serviceTime: "none" , promiseTime: "none" , toSure: "none" , toDo: "none" , type: "" , finished: "none" , ser: "none" , //服务时需要展现的 jiaz: "block" , //家政时需要不展现的 reurls:[], accountArray:[], jobAccount: "none" , //工单收费说明展示 unicode: "" , textarea: "block" }, onShow: function (e){ this .loading() }, onLoad: function (e) { this .setData({ orderId: e.orderId, }) this .loading() qqmapsdk = new QQMapWX({ key: 'NUZBZ-XBSWQ-ZH65L-GRULJ-NJL5K-IBBD4' }); }, loading(){ var _this = this ; req.getJobAccount({ id: _this.data.orderId }, data => { console.log(data) _this.setData({ accountArray: data }) }) req.findTicketDetail({ id: _this.data.orderId }, data => { _this.setData({ dataList: data }) if (_this.data.dataList.faultImg!= "" ){ var len = _this.data.dataList.faultImg.split( "|" ).length var url = [] for ( var i = 0; i < len; i++) { url[i] = api.API_BASE.substring(0, api.API_BASE.length - 1) + _this.data.dataList.faultImg.split( "|" )[i]; } _this.setData({ urls: url }) } }) }, openCalendar1() { $wuxCalendar().open({ value: this .data.date, onChange: (values, displayValues) => { console.log( 'onChange' , values, displayValues) this .setData({ date: displayValues, }) }, }) }, dateSure: function (e){ var _this= this console.log( "date=" + this .data.date[0]) if ( this .data.date[0]==undefined){ _this.setData({ textarea: "none" , }) $wuxDialog().alert({ resetOnClose: true , title: '提示' , content: '请选择上门服务时间!' , onConfirm(e) { _this.setData({ textarea: "block" , }) }, }) } else { req.sureDate({ date: this .data.date[0], id: this .data.dataList.id }, data => { wx.navigateBack({ changed: true }); }) } }, inputTyping: function (e) { //获取页面栈 var pages = getCurrentPages(); if (pages.length > 1) { //上一个页面实例对象 var prePage = pages[pages.length - 2]; //关键在这里 prePage.changeData(e.detail.value) } }, previewImage(e) { const { current } = e.currentTarget.dataset const { urls } = this .data wx.previewImage({ current, urls, }) }, finish: function (e){ var _this= this wx.navigateTo({ url: '../finishJob/finishJob?orderId=' + _this.data.dataList.id + '&unicode=' +_this.data.unicode , }) }, phoneCall: util.throttle( function (e) { wx.makePhoneCall({ phoneNumber: e.currentTarget.dataset.replyPhone, success: function () { console.log( "成功拨打电话" ) }, }) }, 2000), searchLocation: util.throttle( function (){ var _this= this ; var lng=0; var lat=0; qqmapsdk.geocoder({ address: _this.data.dataList.areaName + _this.data.dataList.address, complete: res => { console.log( "res=" + JSON.stringify(res)); //经纬度对象 lng = res.result.location.lng; lat = res.result.location.lat; _this.setLocation(lat,lng); } }) },2000), setLocation: function (lat,lng){ var _this = this ; wx.getLocation({ //获取当前经纬度 type: 'wgs84' , //返回可以用于wx.openLocation的经纬度,官方提示bug: iOS 6.3.30 type 参数不生效,只会返回 wgs84 类型的坐标信息 success: function (res) { wx.openLocation({ //使用微信内置地图查看位置。 latitude: lat, //要去的纬度-地址 longitude: lng, //要去的经度-地址 name: _this.data.dataList.address, address: _this.data.dataList.areaName }) } }) }, scanQR: function (e){ var _this= this wx.scanCode({ success(res){ var uc = res.result.substr(res.result.length - 19, 19) req.checkUnicode({ unicode: uc }, data => { console.log(data) if (data.result== "1" ){ _this.setData({ unicode: uc }) } else { _this.setData({ textarea: "none" , }) $wuxDialog().alert({ resetOnClose: true , title: '提示' , content: '该二维码无法识别!' , onConfirm(e) { _this.setData({ textarea: "block" , }) }, }) } }) } }) } }) |
searchLocation: util.throttle(
function
(){
var
_this=
this
;
var
lng=0;
var
lat=0;
qqmapsdk.geocoder({
address: _this.data.dataList.areaName + _this.data.dataList.address,
complete: res => {
console.log(
"res="
+ JSON.stringify(res));
//经纬度对象
lng = res.result.location.lng;
lat = res.result.location.lat;
_this.setLocation(lat,lng);
}
})
},2000),
_this.data.dataList.areaName + _this.data.dataList.address
确定这两个有值吗?
按你主题贴后来编辑的210行代码里
data里dataList是空的
然后无论是onLoad还是loading里面都没有给这两个赋值,所以,建议放出完整代码
app.json中permission配置了吗?
确认是否在app.json里写入参数
{
"pages"
: [
"pages/index/index"
],
"permission"
: {
"scope.userLocation"
: {
"desc"
:
"你的位置信息将用于小程序位置接口的效果展示"
}
}
}
是否把apis.map.qq.com添加进安全域名