Unable to get GPS coordinates using Javascript on browser in Android

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 23:13:25
axs

Well I did further search and found a solution. I am posting these links here as answer to my question for anyone who comes till here looking for answers.

I had to add these lines in my java code before loading the url and then I was able to see the geo-coordinates.

    webView.getSettings().setGeolocationEnabled(true);
    webView.setWebChromeClient(new WebChromeClient() {
         public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
            // callback.invoke(String origin, boolean allow, boolean remember);              
            callback.invoke(origin, true, false);
         }
        });

For more information follow these two links -

On an Android 6.0 phone (not sure about other versions), this was killing it for me in my build.gradle file:

targetSdkVersion: 23

reducing that to

targetSdkVersion 21

fixed my issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!