下面的脚本在Firefox和Chrome中运行良好,但在Internet Explorer 11中,它总是失败(位置_不可用)。
我已将浏览器设置为允许职位请求,并同意浏览器在请求权限时提示我。
我几乎可以肯定,几个月前,当我最后一次试验它的时候,它工作得很好。在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>

此外,我在IE11中也会遇到同样的失败,当我尝试http://html5demos.com/geo时,火狐和Chrome都可以正常工作。

最佳答案

是否启用定位服务?
我也遇到过同样的问题,在我的Windows 2016中启用了位置服务后,它就工作了。
This page shows how to enable the Location Service in windows 10

10-01 13:48