# Geolocation not enabled in webview on Android

**URL:** <https://forums.fusetools.com/t/geolocation-not-enabled-in-webview-on-android/1374>\
**Category:** General\
**Created:** [September 14, 2017, 2:25pm UTC](https://forums.fusetools.com/t/geolocation-not-enabled-in-webview-on-android/1374 "2017-09-14T14:25:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt3](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@matt3](https://forums.fusetools.com/u/matt3)\
**Post date:** [September 14, 2017, 2:25pm UTC](https://forums.fusetools.com/t/geolocation-not-enabled-in-webview-on-android/1374/1 "2017-09-14T14:25:23Z")

</div>

Looking at the generated code, `WebViewForeign.java`, geolocation isn’t enabled in the webview. This stops you being able to run a location query in the browser which is a pain.

```auto
    public static Object CreateWebView321(final boolean zoomEnabled,final boolean scrollEnabled)
    {
        ScrollableWebView wv = new ScrollableWebView(com.fuse.Activity.getRootActivity());
        wv.getSettings().setJavaScriptEnabled(true);
        wv.getSettings().setUseWideViewPort(true); //enabled viewport meta tag
        wv.getSettings().setLoadWithOverviewMode(true); //mimic iOS Safari and Android Chrome
        wv.getSettings().setSupportZoom(zoomEnabled);
        wv.getSettings().setBuiltInZoomControls(zoomEnabled);
        wv.getSettings().setDomStorageEnabled(true);
        wv.setAllowScroll(scrollEnabled);
        
        return wv;
    }

```

~~Adding these lines would enable GPS location. They would have no effect unless the ACCESS\_LOCATION and ACCESS\_FINE\_LOCATION permissions were set in the manifest which you can force by loading the FuseJS/Geolocation module.~~

```auto
       wv.getSettings().setGeolocationEnabled(true);
       wv.setWebChromeClient(new WebChromeClient(){
            @Override public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
                callback.invoke(origin, true, false);
            }
        });

```

My mistake, there is a webchromeclient created further up which means the code would need moving a little, I was posting before I tested.

In `WebViewForeign.java` add

```auto
wv.getSettings().setGeolocationEnabled(true);

```

and in FuseWebChromeClient.java add

```auto
import android.webkit.GeolocationPermissions.Callback;

...
...

		@Override public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
			callback.invoke(origin, true, false);
		}

```

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [September 14, 2017, 2:39pm UTC](https://forums.fusetools.com/t/geolocation-not-enabled-in-webview-on-android/1374/2 "2017-09-14T14:39:13Z")

</div>

Thanks for the input! I’ve logged [a ticket](https://github.com/fusetools/fuselibs-public/issues/457) about this now, so please check the progress there.

---

<div class="post-metadata">

**Author:** ![matt3](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@matt3](https://forums.fusetools.com/u/matt3)\
**Post date:** [September 14, 2017, 3:02pm UTC](https://forums.fusetools.com/t/geolocation-not-enabled-in-webview-on-android/1374/3 "2017-09-14T15:02:19Z")

</div>

Thank you

I was too hasty typing in the code … check correction above. Simpler code but needs to be split into in 2 places. With code in place (some rapid copying while build happened) this is the result - a successful GPS location in WebView.

 ![file](https://s3.us-east-2.amazonaws.com/fuse-legacy-forum-assets/wz9ysggclQxj-image-1505401259840.png)

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [September 14, 2017, 3:04pm UTC](https://forums.fusetools.com/t/geolocation-not-enabled-in-webview-on-android/1374/4 "2017-09-14T15:04:34Z")

</div>

Please add those details to the ticket.

---

<div class="post-metadata">

**Author:** ![matt3](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@matt3](https://forums.fusetools.com/u/matt3)\
**Post date:** [September 14, 2017, 3:05pm UTC](https://forums.fusetools.com/t/geolocation-not-enabled-in-webview-on-android/1374/5 "2017-09-14T15:05:41Z")

</div>

> **Uldis wrote:**
> 
> Please add those details to the ticket.

Already done. Thank you.
