uni-app IOS 调用 plus.geolocation.getCurrentPosition 报错

uni-app IOS 调用 plus.geolocation.getCurrentPosition 报错

示例代码:

let posOpts = posOpts =  {provider:'amap',enableHighAccuracy:true,timeout:10000,geocode:true,coordsType:'gcj02'}  
plus.geolocation.getCurrentPosition(function(result){  
    callback && callback(result)  
}, function(e){  
    that.geolocation();  
},posOpts);

操作步骤:

let posOpts = posOpts =  {provider:'amap',enableHighAccuracy:true,timeout:10000,geocode:true,coordsType:'gcj02'}  
plus.geolocation.getCurrentPosition(function(result){  
    callback && callback(result)  
}, function(e){  
    that.geolocation();  
},posOpts);

预期结果:

期望正常运行

实际结果:

现在报错

bug描述:

2.8.8 版本
Android 正常运行
IOS 调用 plus.geolocation.getCurrentPosition 报错如下:
[JS Framework] Failed to execute the callback function:
16:49:58.959 TypeError: n.setTimeout is not a function. (In ‘n.setTimeout(function(){c(t),t=null,i(new r(r.TIMEOUT,“Position retrieval timed out.”))},o)’, ‘n.setTimeout’ is undefined) __ERROR

编辑器版本切换至2.8.7 代码正常执行


更多关于uni-app IOS 调用 plus.geolocation.getCurrentPosition 报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

2.8.11 同样有问题 加载定位出错 TypeError: n.setTimeout is not a function at a (eval at <anonymous> (Runtime.IOS.js:385), <anonymous>:2:27055)
at u (eval at <anonymous> (Runtime.IOS.js:385), <anonymous>:2:28107)
at Object.watchPosition (eval at <anonymous> (Runtime.IOS.js:385), <anonymous>:2:28592)
at o.startPositioning (patrol.vue:235)
at o.getUserLoca (patrol.vue:186)
at o.mounted (patrol.vue:110)
at Ke ()
at o.Hr [as __call_hook] ()
at Array.<anonymous> ()
at Hn.Bu () uni-app:///pages/patrol/patrol.vue:112

更多关于uni-app IOS 调用 plus.geolocation.getCurrentPosition 报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html


console.log(“vvvvvvvvv”); let posOpts = {provider:‘amap’,enableHighAccuracy:true,timeout:10000,geocode:true,coordsType:‘gcj02’} ; console.log(“vvvvvsdfasdvvvv”); plus.geolocation.getCurrentPosition(function(result){ console.log(“ak::::” JSON.stringify(result)); }, function(e){ console.log(“asdfajlsdfk::::” JSON.stringify(e)); },posOpts);
没有复现你描述的问题

这个错误是由于uni-app 2.8.8版本在iOS平台上的兼容性问题导致的。从错误信息看,是setTimeout函数在定位模块中未正确定义。

解决方案有以下几种:

  1. 降级到2.8.7版本(您已验证可行)
  2. 等待官方修复后升级到新版本
  3. 临时修改代码,在调用前确保setTimeout可用:
if(typeof setTimeout === 'undefined') {
    global.setTimeout = function(){};
}
回到顶部