I am trying to render google map embedded in a webpage through WebView. Though it works on the emulator it's not working on device (android 2.3.6 and 4.4.2). Below is my code:
WebView webview = (WebView) findViewById(R.id.webView1);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
String url = "http://mywebsite.com/mobile_map.php";
webView.loadUrl(url);
I tried a direct url and not my webpage as "https://www.google.co.in/maps/@20.3008841,85.7699553,12z?hl=en" This also works on AVD but not on devices.
Tried to implement an AsysnkTask and also handle the ssl error as follows:
public class LoadSocialNetworkUrlTask extends AsyncTask<String, String, Void> { protected void onPreExecute() { dialog = new ProgressDialog(MapActivity.this); dialog.setMessage("Loading,Please wait..."); dialog.setIndeterminate(true); dialog.setCancelable(true); dialog.show(); } protected void onProgressUpdate(final String... url) { try { ((WebView) webView).getSettings().setJavaScriptEnabled(true); ((WebView) webView).setBackgroundColor(Color.TRANSPARENT); ((WebView) webView).setWebViewClient(new WebViewClient() { @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); // Ignore SSL certificate errors } @Override public void onPageFinished(WebView view, String url) { // TODO hide your progress image super.onPageFinished(view, url); dialog.dismiss(); } }); ((WebView) webView).loadUrl(url[0]); } catch (Exception e) { e.printStackTrace(); dialog.dismiss(); } } @Override protected Void doInBackground(String... url) { try { publishProgress(url); } catch (Exception e) { e.printStackTrace(); dialog.dismiss(); } return null; } }
but the same result. What am I missing? Should not we display a page containing map in webview and handle map directly with api? Do I have to make some setting in the device? (the device is connected to internet.)