我正在为使用Google地图和地理位置的网站编写包装器应用程序。我遇到的问题是,在正常的浏览器中,页面正常运行,但是在WebView中,两指缩放无法正常工作,字面上充满了此错误:

05-24 08:14:28.504: E/Web Console(21166): Uncaught TypeError: Cannot read property 'getBoundingClientRect' of null at http://<mydomain>/index.php:28

麻烦的是,该函数仅在Google的JS代码中使用,而不在我们的代码中使用,因此我对此没有太多功能。我应该如何解决呢?

这是一些(可能)与您相关的资源,且审查制度最少。

myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebChromeClient(new WebChromeClient() {
    public void onProgressChanged(WebView view, int progress) {
        mk.setTitle(getString(R.string.loading));
        mk.setProgress(progress * 100);
        if(progress == 100) {
            mk.setTitle(R.string.app_name);
        }
    }

    public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
        callback.invoke(origin, true, false);
    }
});
myWebView.setWebViewClient(new MyWebViewClient());
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUserAgentString(getString(R.string.useragent));
webSettings.setGeolocationEnabled(true);
webSettings.setBuiltInZoomControls(false);
webSettings.setGeolocationDatabasePath("/data/data/com.mypackage.myapp");
myWebView.addJavascriptInterface(new JSInterface(this), "androidapp");
myWebView.loadUrl(HOMEURL);

最佳答案

用来调用getBoundingClientRect的对象都是null -因此,这就是问题的开始。您能否查看原始的JS代码(在网站上称为Google的API)?

关于android - Android WebView上的getBoundingClientRect错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10731745/

10-13 04:40