none
WPF WebBrowser Control on Win8.1 and navigator.geolocation.getCurrentPosition issue

    Question

  • Hi Anyone,

    I have not been able to modify the WPF windows.controls.webbrowser to load a resource .html file and display the Computers location.

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta charset="utf-8" />

    Script

    <script>
    
            window.onload = getMyLocation;
    
            function getMyLocation() {
    
                // Check if the browser supports the Geolocation API
                if (navigator.geolocation) {
    
                    // we can specify how the geolocation computes its value
                    var postionOptions = { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 };
    
                    // call getCurrentPosition method of the API
                    // getCurrentPosition(successHander, errorHandler, positionOptions)
                    navigator.geolocation.getCurrentPosition(displayLocation, displayError, postionOptions);
                }
                else {
                    alert("No geolocation support in the browser\n" + navigator.userAgent);
                }
            }
    </script>

    When I view the navigator information I get

    when I load the same page directly into IE11 everything is fine. So my issue seems to be around the WebBrowser Document Mode as it is only representing IE7 :(.

    I have tried to set the FEATURE_BROWSER_EMULATION in Registry Local machine with no success.

    Can anyone please help me get the navigator.geolocation.getCurrentPosition to work in my application.

    Full Code

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta charset="utf-8" />
        <title>Geolocation HTML5</title>
        <script>
    
            window.onload = getMyLocation;
    
            function getMyLocation() {
                var divAgentString = document.getElementById('agentstring');
                divAgentString.innerHTML = "UserAgent:\n" + navigator.userAgent + "\nAppName:\n" + navigator.appName;
    
                // Check if the browser supports the Geolocation API
                if (navigator.geolocation) {
                    var divgeolocationexists = document.getElementById('geolocationexists');
                    divgeolocationexists.innerHTML = "True";
    
                    // we can specify how the geolocation computes its value
                    var postionOptions = { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 };
    
                    // call getCurrentPosition method of the API
                    // getCurrentPosition(successHander, errorHandler, positionOptions)
                    navigator.geolocation.getCurrentPosition(displayLocation, displayError, postionOptions);
                }
                else {
                    alert("No geolocation support in the browser");
                }
            }
    
            function displayLocation(position) {
                // get the latitude and longitude
                var latitude = position.coords.latitude;
                var longitude = position.coords.longitude;
    
    
                // get location div and show the latitude longitude and the accuracy
                var divLocation = document.getElementById('location');
                divLocation.innerHTML = "I am at Latitude :" + latitude + ", Longitude : " + longitude;
                divLocation.innerHTML += " with " + position.coords.accuracy + " meters accuracy";
            }
    
    
            // error handler
            function displayError(error) {
    
                var errorTypes = {
                    0: "Unknown Error",
                    1: "Permission denied by user",
                    2: "Position is not available",
                    3: "Request timed out"
                };
    
                var errorMessage = errorTypes[error.code];
    
                if (error.code == 0 || error.code == 2) {
                    errorMessage = errorMessage + " " + error.message;
                }
    
                var divLocation = document.getElementById('location');
                divLocation.innerHTML = errorMessage;
            }
        </script>
    </head>
    <body>
        <div id="agentstring"></div>
        <div id="geolocationexists"></div>
        <div id="location"></div>
    </body>
    </html>
    

    Regards Stuart


    • Edited by Stuart Paice Wednesday, July 2, 2014 6:53 AM Updated Code Base
    Wednesday, July 2, 2014 6:30 AM

Answers

  • By setting FEATURE_BROWSER_EMULATION, you correctly move the page to IE10+ document mode. Unfortunately, WebOC consent UIs were never implemented for the GeoLocation feature and thus it is not supported to use GeoLoc from within a WebOC-hosting application.
    Thursday, July 3, 2014 3:53 PM

All replies