IE 11中的geoLocation.GetCurrentPosition始终失败

时间:2015-02-18 18:23:03

标签: 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>

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

4 个答案:

答案 0 :(得分:1)

我在IE11中遇到了同样的问题。 我必须将enableHighAccuracy设置为false才能使其正常工作。一旦我这样做,IE按预期工作。

答案 1 :(得分:1)

您是否启用了位置服务?

我遇到了同样的问题,我在Windows 2016中启用了位置服务后,它运行了。

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

答案 2 :(得分:0)

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

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

答案 3 :(得分:-2)

啊哈,刚发现了什么。 Chrome显然使用WIFI接入点来帮助查找位置。

如果没有即时GPS信号,IE11(和边缘)会回落到Windows设置中的默认位置。