<!DOCTYPE html><html><body><pid="demo">Click the button to get your coordinates:</p><buttononclick="getLocation()">Try It</button><script>varx=document.getElementById("demo");functiongetLocation(){console.info("getLocation working")if(navigator.geolocation){navigator.geolocation.getCurrentPosition(showPosition,showError);}else{x.innerHTML="Geolocation is not supported by this browser.";}}functionshowPosition(position){x.innerHTML="Latitude: "+position.coords.latitude+"<br>Longitude: "+position.coords.longitude;}functionshowError(error){switch(error.code){caseerror.PERMISSION_DENIED:x.innerHTML="User denied the request for Geolocation."break;caseerror.POSITION_UNAVAILABLE:x.innerHTML="Location information is unavailable."break;caseerror.TIMEOUT:x.innerHTML="The request to get user location timed out."break;caseerror.UNKNOWN_ERROR:x.innerHTML="An unknown error occurred."break;}}</script></body></html>
finalWebViewwebView=newWebView(this);addContentView(webView,newLayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));WebSettingssettings=webView.getSettings();settings.setJavaScriptEnabled(true);settings.setGeolocationEnabled(true);settings.setGeolocationDatabasePath(getFilesDir().getPath());webView.setWebChromeClient(newWebChromeClient(){@OverridepublicvoidonGeolocationPermissionsHidePrompt(){super.onGeolocationPermissionsHidePrompt();Log.i(LOGTAG,"onGeolocationPermissionsHidePrompt");}@OverridepublicvoidonGeolocationPermissionsShowPrompt(finalStringorigin,finalCallbackcallback){AlertDialog.Builderbuilder=newAlertDialog.Builder(MainActivity.this);builder.setMessage("Allow to access location information?");OnClickListenerdialogButtonOnClickListener=newOnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intclickedButton){if(DialogInterface.BUTTON_POSITIVE==clickedButton){callback.invoke(origin,true,true);}elseif(DialogInterface.BUTTON_NEGATIVE==clickedButton){callback.invoke(origin,false,false);}}};builder.setPositiveButton("Allow",dialogButtonOnClickListener);builder.setNegativeButton("Deny",dialogButtonOnClickListener);builder.show();super.onGeolocationPermissionsShowPrompt(origin,callback);Log.i(LOGTAG,"onGeolocationPermissionsShowPrompt");}});webView.loadUrl("file:///android_asset/geolocation.html");