google-mapsgoogle-places-apiandroid-mapsandroid-4.0-ice-cream-sandwichgoogle-places

Embedded Google Map can't get current location in WebView


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?


Solution

  • 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);
            }
        });