Reputation: 896
I have a web page in which location is getting detected in web browser successfully. And based on location my results are filtered out. I am running same website url in a webview of android app. But in android app that location detection javascript is not working. Any suggestions what to do here?
Thanks in advance.
Upvotes: 0
Views: 1516
Reputation: 31
Doing the above still didn't work for me, but adding some additional code did - see Android Webview Geolocation
I added the following to my webview object
// enable geolocationEnabled
webview.getSettings().setGeolocationEnabled(true);
// enable JavaScriptCanOpenWindowsAutomatically, not sure if this is needed
webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
// set setWebChromeClient
webview.setWebChromeClient(new WebChromeClient() {
public void onGeolocationPermissionsShowPrompt(String origin, android.webkit.GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
}
});
For some reason android.webkit.GeolocationPermissions.Callback
had to be a fully qualify className, after adding it as an import it was still not recognized by the Eclipse IDE.
Upvotes: 3
Reputation: 1711
Just one question: Does the location detection JS work in the Android Browser (not in the Android WebView)?
One thing to try is add the following to your manifest file:
<manifest ... >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
...
</manifest>
The second is to setJavaScriptEnabled(true) in your webview. I just noticed someone answered this below.
Read more here: http://developer.android.com/guide/topics/location/obtaining-user-location.html
Upvotes: 1
Reputation: 3772
You should enable javascript for webview.
To do that,
wv = (WebView) findViewById(R.id.web_view);
wv.getSettings().setJavascriptEnabled(true);
Upvotes: 1