Search code examples
c#htmlgeolocationuwp

C# Uwp app webbrowser control cannot get device location


I am developing a web view universal windows application. In fact my mobile ready website will be shown within a web view or webbrowser control in windows universal application..

Using the website directly from Edge in mobile (or chrome in desktop etc) the app notifies the user to allow using location as it should (HTML Geolocation API ).

However in my app using web browser control this is not happening. It is not able to run the script or something.

I have given grant access to user's location in the app but still no action is taken.

What else can I do in order to get user's location within an app that uses webbrowser ?


Solution

  • I found the solution.

    You have to fire the PermissionRequested event. And in this event you have to execute the Allow method of the WebViewPermissionRequestedEventArgs object. Something like this:

    private void webView_PermissionRequested(WebView sender, WebViewPermissionRequestedEventArgs args)
        {
            if (args.PermissionRequest.PermissionType == WebViewPermissionType.Geolocation)
                args.PermissionRequest.Allow();
        }