【问题标题】:geoLocation.GetCurrentPosition always fails in IE 11geoLocation.GetCurrentPosition 在 IE 11 中总是失败
【发布时间】:2015-04-19 21:25:07
【问题描述】:

以下脚本在 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 都可以正常工作。

【问题讨论】:

  • 能否请您出示您的脚本参考资料?
  • 不确定“脚本引用”是什么意思。我确实在页面顶部引用了modernizr-2.8.3.js 的本地副本,以及在上面显示的脚本之前的jquery-2.1.3.js、bootstrap.js 和respond.js 的本地副本。我遇到的问题不仅限于我的代码。
  • 你有没有想过这个问题?我有同样的问题,我找不到解决办法
  • 我的 IE11 也有同样的问题 - 有谁知道解决方案
  • 如果你有这个问题,并且这个问题没有找到答案,请投票。

标签: html internet-explorer geolocation internet-explorer-11


【解决方案1】:

您是否启用了定位服务?

我也遇到了同样的问题,在我的 windows 2016 中启用定位服务后它就可以工作了。

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 我将 enableHighAccuracy 设置为 false,但它不起作用。我的 IE 版本是 11.1715.14393.0 。
    【解决方案3】:

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

    进行这些更改后,http://html5demos.com/geo 现在为我工作了。一开始没有。

    【讨论】:

    • “永远不允许网站请求您的实际位置”已取消选中。如原始问题中所述,浏览器已设置为允许位置请求,并且要求我允许,但无论如何都失败了。
    • 尝试了所有这些解决方案。没有运气。
    【解决方案4】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-31
      • 1970-01-01
      • 1970-01-01
      • 2015-12-27
      • 2019-03-29
      • 2016-08-13
      • 2014-11-09
      • 1970-01-01
      相关资源
      最近更新 更多