IE 11中的geoLocation.GetCurrentPosition始终失败

Pau*_*oni 15 html5 internet-explorer geolocation internet-explorer-11

下面的脚本在FireFox和Chrome中运行良好,但在Internet Explorer 11中,它始终失败(使用POSITION_UNAVAILABLE).

我已将浏览器设置为允许位置请求,并且我同意浏览器在请求权限时提示我的提示.

我几乎可以肯定,几个月前,当我最后一次试验它时,这种方法很好.就IE的设置而言,我还能错过什么?

<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>
Run Code Online (Sandbox Code Playgroud)

此外,当我尝试http://html5demos.com/geo时,我在IE11中遇到同样的失败,其中FireFox和Chrome都能正常工作.

Rom*_*las 0

在“Internet 选项”中,单击“隐私”选项卡。取消选中从不允许网站请求您的物理位置框,然后点击确定。

进行这些更改后,http://html5demos.com/geo现在对我有用。最初没有。

  • “绝不允许网站请求您的物理位置”尚未选中。正如原始问题中提到的,浏览器已经设置为允许位置请求,并且我被请求获得我的许可,但无论如何它都会失败。 (3认同)