Cordova getCurrentPosition()永不返回
问题描述:
我的科尔多瓦版本是6.3.1,我使用的是cordova-plugin-geolocation 2.3.0。
当打电话navigator.geolocation.getCurrentPosition(onSuccess, onError)
,既不onSuccess
或onError
是从来没有这样激动。
我也尝试过使用cordova-plugin-locationservices插件,该插件利用Google Play服务获取用户位置,但获得了相同的结果。
我正在为CyanogenMod 13(Android 6)构建,并且正在使用microG for Google Play服务(这适用于我迄今为止遇到的所有其他应用程序)。
代码如下,提前谢谢。Cordova getCurrentPosition()永不返回
setInterval(function(){
cordova.plugins.locationServices.geolocation.getCurrentPosition(function(pos) { /* cordova-plugin-locationservices */
//navigator.geolocation.getCurrentPosition(function(pos) { /* cordova-plugin-geolocation */
alert('Location determined');
console.log(pos);
}, function(err) {
alert('code: ' + err.code + '\n message: ' + err.message);
});
},3000);
答
你必须给一个超时属性的选择对象,因为如果你不这样做,Android设备将不会触发错误回调,所以你不会看到任何错误。
setInterval(function(){
cordova.plugins.locationServices.geolocation.getCurrentPosition(function(pos) { /* cordova-plugin-locationservices */
//navigator.geolocation.getCurrentPosition(function(pos) { /* cordova-plugin-geolocation */
alert('Location determined');
console.log(pos);
}, function(err) {
alert('code: ' + err.code + '\n message: ' + err.message);
}, { timeout: 5000});
},3000);
谢谢,这个我指出了正确的方向。我最终收到一个错误,指出“接收位置时超时”,它指向我[此处](http://stackoverflow.com/a/21481475/2657558),并解决了该问题。干杯! – Mulletfingers999