简体   繁体   English

无法在Android WebView中显示Google Map

[英]Can't Show Google Map in Android WebView

I have an aspx page which had already integrated google map api and can displayed the google map , then I want to show it in the android webview, but the webview can not be displayed the google map . 我有一个已经集成了google map api的aspx页面,可以显示google map,然后我想在android webview中显示它,但是webview无法显示google map。 this aspx page can run perfectly in android browser. 这个aspx页面可以在Android浏览器中完美运行。

Here is Logcat print: 这是Logcat的打印内容:

I / chromium: [INFO: CONSOLE (210)] "Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys ", source: http: //maps.google.com/maps-api-v3/api/js/25/11/util.js (210) I /铬:[INFO:CONSOLE(210)]“ Google Maps API警告:NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys “,来源:http: //maps.google.com/maps-api-v3/api/js/25/11/util.js(210)

I / chromium: [INFO: CONSOLE (210)] "Google Maps API warning: SensorNotRequired https://developers.google.com/maps/documentation/javascript/error-messages#sensor-not-required ", source: http: //maps.google.com/maps-api-v3/api/js/25/11/util.js (210) I /铬:[INFO:控制台(210)]“ Google Maps API警告:SensorNotRequired https://developers.google.com/maps/documentation/javascript/error-messages#sensor-not-required ”,来源:http: //maps.google.com/maps-api-v3/api/js/25/11/util.js(210)

Here is the code about setting webview: 以下是有关设置Webview的代码:

webView.getSettings().setJavaScriptEnabled(true);//
        webView.getSettings().setGeolocationEnabled(true);//
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setDomStorageEnabled(true);//
        webView.getSettings().setDatabaseEnabled(true);//
        webView.getSettings().setPluginState(WebSettings.PluginState.ON);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
        webView.getSettings().setBlockNetworkImage(false);
        webView.getSettings().setBlockNetworkLoads(false);
        String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
        webView.getSettings().setGeolocationDatabasePath(dir);

Based from your code, I can't find the loadUrl which loads the given URL . 根据您的代码,我找不到加载给定URLloadUrl

Compatibility note. 兼容性说明。 Applications targeting N or later, JavaScript state from an empty WebView is no longer persisted across navigations like loadUrl . N或更高版本为目标的应用程序,来自空WebView的JavaScript状态不再跨loadUrl导航持久化。 For example, global variables and functions defined before calling loadUrl(String) will not exist in the loaded page. 例如,在调用loadUrl(String)之前定义的全局变量和函数在已加载的页面中将不存在。 Applications should use [ addJavascriptInterface(Object, String) ]( https://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object , java.lang.String)) instead to persist JavaScript objects across navigations. 应用程序应使用[ addJavascriptInterface(Object, String) ]( https://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface (java.lang.Object,java.lang.String))代替进行持久化跨导航的JavaScript对象。

To provide a WebView in your own Activity, include a in your layout, or set the entire Activity window as a WebView during onCreate(): 要在您自己的Activity中提供WebView,请在布局中添加,或在onCreate()期间将整个Activity窗口设置为WebView:

WebView webview = new WebView(this);
setContentView(webview);

Then load the desired web page: 然后加载所需的网页:

webview.loadUrl("http://slashdot.org/");

just add this line after webView.getSettings().setJavaScriptEnabled(true);// 只需在webView.getSettings()。setJavaScriptEnabled(true); //之后添加此行

webview.setWebViewClient(new WebViewClient()); webview.setWebViewClient(new WebViewClient());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM