javascript - 错误尝试调用虚拟方法'android.location.Location

标签 javascript angularjs local-storage ibm-mobilefirst

我正在使用 MobileFirst 提供的 WL.Device.Geo.acquirePosition(onGeoLocationSuccess, onGeoLocationFailure, options) 检索设备的位置。

第一次效果很好。我知道了位置,一切都很好。

但是,在应用程序中的某个时刻,我清除了 localStorage。当我这样做时,应用程序变得疯狂,我不断在控制台中收到此错误:

getPosition - error Attempt to invoke virtual method 'android.location.Location com.worklight.androidgap.plugin.WLGPSListener.getLastKnownLocation()' on a null object reference

这就是我的代码的样子:

position();

function position() {

  var options = {
    enableHighAccuracy : false,
    timeout            : 20000,
    maximumAge         : 30000,
    highAccuracyOptions: {
      desiredAccuracy: 50, //meters
      iOSBestAccuracy: WL.Device.Geo.IOS_BEST_ACCURACY
    }
  };

  WL.Device.Geo.acquirePosition(onGeoLocationSuccess, onGeoLocationFailure, options);
}

function onGeoLocationSuccess(position) {
  WL.Logger.info('Got position now ;)');
}

function onGeoLocationFailure(errorObj) {
  console.log('Trying again ');
  position();
}

这就是我在另一个服务中重置 localStorage 的方法

localStorage.clear();

有什么建议吗?

最佳答案

Check for the contents本地存储的;由于您要强制清除整个存储,因此我怀疑您在应用程序运行时期间清除了所需的数据。

仅清除需要清除的内容,而不是全部。

关于javascript - 错误尝试调用虚拟方法'android.location.Location,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34264205/

相关文章:

JavaScript - 游戏。匹配随机生成器生成的两个变量的算法

javascript - 在 javascript 函数参数列表中传递可变数量的参数

javascript - 将 $scope 传递给 Angularjs 中的服务

sql - 将图像上传到Azure(简单表)

jquery - 监听本地存储更改事件

javascript - 在 javascript 中正确写入从 bean 接收到的值

javascript - Javascript 条件可以在数字之间吗?

javascript - 如何在 HTML 中存储和修改来自 md-switch 的 JS 变量?

angularjs - 正确使用 Protractor

html - 页面刷新时保存在localstorage中的变量消失