title: Geo Location Cannot Work Android < 5 version using Webview
body: <p>I am converting website to Android Application. But GeoLocation cannot work on versions below Lollipop. So what should be the workaround?</p>
  
  <p>I have a simple WeBView in My activity_main.xml</p>
  
  <p><strong>My MainActivity.java code:</strong></p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  
  private static final String TAG = MainActivity.class.getSimpleName();
  private WebView myWebView;
  private WebSettings webSettings;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      myWebView = (WebView) findViewById(R.id.webView);
      webSettings = myWebView.getSettings();
  
      myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
      myWebView.getSettings().setBuiltInZoomControls(true);
      myWebView.setWebViewClient(new GeoWebViewClient());
      myWebView.setWebViewClient(new Client());
      myWebView.getSettings().setJavaScriptEnabled(true);
      myWebView.getSettings().setGeolocationEnabled(true);
      myWebView.setWebChromeClient(new GeoWebChromeClient());
      webSettings.setGeolocationEnabled(true);
      if (Build.VERSION.SDK_INT &gt;= 19) {
          myWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
      } else if (Build.VERSION.SDK_INT &gt;= 11 &amp;&amp; Build.VERSION.SDK_INT &lt; 19) {
          myWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
      }
  
     myWebView.loadUrl("http://webrivers.co.in/green_medic/lock_screen.html"); //change with your website
      }
  
      public boolean onKeyDown(int keyCode, KeyEvent event) {
      // Check if the key event was the Back button and if there's history
      if ((keyCode == KeyEvent.KEYCODE_BACK) &amp;&amp; myWebView.canGoBack()) {
          myWebView.goBack();
          return true;
      }
      // If it wasn't the Back key or there's no web page history, bubble up to the default
      // system behavior (probably exit the activity)
      return super.onKeyDown(keyCode, event);
      }
  
      public class GeoWebViewClient extends WebViewClient {
      @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
          // When user clicks a hyperlink, load in the existing WebView
          view.loadUrl(url);
          return true;
      }
      }
  
      public class GeoWebChromeClient extends WebChromeClient {
      @Override
      public void onGeolocationPermissionsShowPrompt(String origin,
  
    GeolocationPermissions.Callback callback) {
          // Always grant permission since the app itself requires location
          // permission and the user has therefore already granted it
          callback.invoke(origin, true, false);
      }
     }
  
     public class Client extends WebViewClient {
      ProgressDialog progressDialog;
  
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
          // If url contains mailto link then open Mail Intent
          if (url.contains("mailto:")) {
              // Could be cleverer and use a regex
              //Open links in new browser
              view.getContext().startActivity(
                      new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
              // Here we can open new activity
              return true;
          } else {
              // Stay within this webview and load url
              view.loadUrl(url);
              return true;
          }
      }
  
      //Show loader on url load
      public void onPageStarted(WebView view, String url, Bitmap favicon) {
          // Then show progress  Dialog
          // in standard case YourActivity.this
          if (progressDialog == null) {
              progressDialog = new ProgressDialog(MainActivity.this);
              progressDialog.setMessage("Loading...");
              progressDialog.show();
          }
      }
  
      // Called when all page resources loaded
      public void onPageFinished(WebView view, String url) {
          try {
              // Close progressDialog
              if (progressDialog.isShowing()) {
                  progressDialog.dismiss();
                  progressDialog = null;
              }
          } catch (Exception exception) {
              exception.printStackTrace();
          }
      }
     }
     }
  </code></pre>
  
  <p><strong>Android 5 below version Geo location work fine, but cannot get geo location automatic, once load google map then work geo location</strong> please help me.</p>