Embedded Google Map can't get current location in WebView

user5243421 picture user5243421 · May 10, 2013 · Viewed 8.7k times · Source

I followed this tutorial: http://android-er.blogspot.com/2013/03/embed-google-map-in-webview.html

I'm trying to just use the Google Map in the WebView, but it can't get my current location. I've enabled JavaScript on the WebView. What else do I have to enable?

Does anyone know why that might be? Shouldn't it prompt me to use my current location?

Note that I am not interested in using a MapView as an alternative whatsoever. I'm trying to find out what I need to set on the WebView or maybe on the device's location services?

Answer

Kumait picture Kumait · Jul 26, 2013

You should permit the web view to access your location by overriding the method onGeolocationPermissionsShowPrompt like this:

webView.setWebChromeClient(new WebChromeClient(){

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