PhoneGap的构建地理定位错误的NPObject调用方法 [英] Phonegap build geolocation Error calling method on NPObject

查看:180
本文介绍了PhoneGap的构建地理定位错误的NPObject调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与PhoneGap的/科尔多瓦地理位置插件有问题。
我创建一个使用用户地理位置,以检查它们是否接近的位置,然后做一些东西与一个应用程序。

I have a problem with the phonegap/cordova geolocation plugin. I'm creating a application that uses the users geolocation to check if they are close to a position and then do some stuff with that.

我不断收到此错误:错误调用NPObject方法。
我搬来搬去的code和创造了一些新的功能有更具体的功能,发现失败的code。

I kept getting this error: Error calling method on NPObject. I moved the code around and created some new functions to have more specific functions and found the failing code.

我把它放在一个try ... catch来获得更好的错误:

I put it in a try ... catch to get better errors:

getLocation: function()
{
    try
    {
        navigator.geolocation.getCurrentPosition(this.onSuccess, this.onError);
    }
    catch(err)
    {
        console.log("Error code: "+err.code);
        console.log("Error message: "+err.message);

    }
}

不过,我仍然只能得到同样的错误
错误code:未定义
错误信息:错误的NPObject调用方法

But I still only get the same error Error code: undefined Error message: Error calling method on NPObject.

我使用的PhoneGap构建和已经添加了地理位置插件。

I'm using phonegap build and have added the plugin for geolocation.

推荐答案

当您尝试使用方法从JavaScript接口调用,与UI交互它发生。解决这个问题是这样的:

It happens when you try, using method called from javascript interface, to interact with UI. Solve it in this way:

class mJSInterface()
{

public void myFunction()
{
  runOnUiThread(new Runnable() {

        public void run() {
            //Code that interact with UI
        }
    });

}
}

这篇关于PhoneGap的构建地理定位错误的NPObject调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆