2

I developed a web application and I tried to use webview. Everything works fine except the geolocation (which works perfectly in web)

Does anybody have an example of a webview with geolocation?

This is the code for webview:

package com.androidpeople.view;

    import android.app.Activity;
    import android.os.Bundle;
    import android.webkit.WebView;
    
    public class WebViewExample extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        WebView webView = (WebView) findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://myweb.com");
        webView.setWebViewClient(new HelloWebViewClient());
    }
}
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
user592376
  • 21
  • 4

2 Answers2

0

Add these lines in my java code before loading the url and then you will be 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 the solution in this link -

Community
  • 1
  • 1
axs
  • 1,156
  • 1
  • 10
  • 15
0

Try:

myWebView.getSettings().setGeolocationDatabasePath(<yourpath>);
myWebView.getSettings().setGeolocationEnabled(true);  
Renaud Cerrato
  • 1,297
  • 16
  • 20