1

我正在为一个使用谷歌地图和地理位置的网站编写一个包装应用程序。我遇到的问题是,在普通浏览器中,页面运行正常,但在 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

麻烦的是,这个函数只用在谷歌的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);
4

2 回答 2

2

无论使用什么对象来调用getBoundingClientRect都是null- 所以这就是你的问题的开始。你能看一下原始的JS代码(在网站上,调用谷歌的API)吗?

于 2012-05-24T09:44:43.867 回答
0

我在为 webview 设置自定义用户代理时遇到了这个问题。在我将它改回默认用户代理后,问题就解决了。

于 2015-01-08T02:17:27.207 回答