第二次触发onshow函数,函数中的调用函数真机测试时不执行
发布于 5 年前 作者 shiwei 13948 次浏览 来自 问答

利用微信内置地图进行实际开发时,发现熄屏后再次触发show函数时,show函数提示被触发,在show函数中放的是一个定时器,定时器中放着一个API为wx.getLocation,show函数被触发后,定时器也被触发,可是wx.getLocation没有被触发,并且一直报错,错误信息为errCode: -1, errMsg: “getLocation:fail:timeout”。

2 回复

onShow: function() {

var self = this;

if (key1) {

if (timer) {

clearInterval(timer);

};

console.log(‘show’);

self.shishiyundong(‘show’);

///

shishiyundong: function(kr) {

if (kr.type == ‘tap’) {

kr = ‘yundong’;

}

var that = this;

var objj;

timer = setInterval(function() {

wx.getLocation({

type: “gcj02”,

success: function(res) {

// console.log(res);

dangqian = res;

objj = {

latitude: dangqian.latitude,

longitude: dangqian.longitude

};

plll.push(objj);

console.log(objj, plll, kr);

//设置polyline属性,将路线显示出来

that.setData({

polyline: [{

points: plll,

color: ‘#000000’,

width: 2,

}],

marker: [{

markerId: 0,

iconPath: ‘…/image/wz.png’,

longitude: objj.longitude,

latitude: objj.latitude,

width: 30,

height: 30,

}],

});

},

fail: function(res) {}

});

}, 1000);

},

贴下你onShow的代码呢

回到顶部