Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

geoLocation.GetCurrentPosition always fails in IE 11

The script below works fine in FireFox and Chrome, but in Internet Explorer 11, it always fails (with POSITION_UNAVAILABLE).

I have set the browser to allow requests for position, and I agree to the prompt the browser presents me when requesting permission.

I'm almost certain that this worked fine a few months ago when I was last experimenting with it. What could I be missing as far as IE's settings?

<script type="text/javascript">
    $(document).ready(function () {
        if (Modernizr.geolocation)
        {
            navigator.geolocation.getCurrentPosition(positionSuccess, positionError, { enableHighAccuracy: true, maximumAge: 60000, timeout: 10000 })
        }
        else
        {
            $("#GeoError").html("Unable to retrieve current position.")
        }
    });

    function positionSuccess(position)
    {
        $("#Latitude").val(position.coords.latitude);
        $("#Longitude").val(position.coords.longitude);
    }

    function positionError(error)
    {
        var message = "";

        // Check for known errors
        switch (error.code) {
            case error.PERMISSION_DENIED:
                message = "This website does not have your permission to use the Geolocation API";
                break;
            case error.POSITION_UNAVAILABLE:
                message = "Your current position could not be determined.";
                break;
            case error.PERMISSION_DENIED_TIMEOUT:
                message = "Your current position could not be determined within the specified timeout period.";
                break;
        }

        // If it's an unknown error, build a message that includes 
        // information that helps identify the situation, so that 
        // the error handler can be updated.
        if (message == "") {
            var strErrorCode = error.code.toString();
            message = "Your position could not be determined due to " +
                      "an unknown error (Code: " + strErrorCode + ").";
        }

        $("#GeoError").html(message)
    }
</script>

Also, I get the same failure in IE11 when I try http://html5demos.com/geo, where both FireFox and Chrome work fine.

like image 453
Paul Marangoni Avatar asked Feb 18 '15 18:02

Paul Marangoni


People also ask

Why is geolocation not accurate?

According to Google's new policy, smartphones running Android 10 are required to grant GPS permission for relevant apps to be provided with location data. Your GPS info may be inaccurate when your device screen is turned off depending on which option you selected in App permissions.

What does geolocation getCurrentPosition return?

geolocation. getCurrentPosition is an asynchronous function. It returns the device's current position to the [geolocationSuccess](parameters/geolocationSuccess.

What is navigator geolocation getCurrentPosition?

Description. The getCurrentPosition method retrieves the current geographic location of the device. The location is expressed as a set of geographic coordinates together with information about heading and speed. The location information is returned in a Position object.

What is geolocation error?

If you receive this error, it means your device supports geolocation but your mobile browser is unable to access it. To fix this, you need to have two things right: Your mobile device's location services (GPS) needs to be enabled. Your mobile browser needs to have an access to the geolocation provided by the phone.


2 Answers

Does you enable the Location Service?

I have had the same issue, it worked after I enabled the Location Service in my windows 2016.

This page shows how to enable the Location Service in windows 10.

like image 155
cocoa Avatar answered Oct 07 '22 19:10

cocoa


I have had the same issue in IE11 only. I had to set enableHighAccuracy to false to get it to work. Once I did that IE worked as expected.

like image 41
Ben Cameron Avatar answered Oct 07 '22 20:10

Ben Cameron