【问题标题】:In new chrome (44.0.2403.157) geolocations doesnt works在新的 chrome (44.0.2403.157) 中,地理位置不起作用
【发布时间】:2015-11-26 11:38:06
【问题描述】:

它似乎在 Linux Mint 和 Windows 上的 MacOs 上的新 chrome 版本中 地理位置不起作用! 它的返回错误: "ERROR(2): 'https://www.googleapis.com/' 的网络位置提供程序:返回错误代码 403。"

有人有同样的问题吗?

【问题讨论】:

  • 似乎在 Canary (47.0.2498.0) 中也出现问题。
  • HTML5 地理位置对我来说也坏了。昨天工作正常。 Google Chrome 版本 44.0.2403.157(64 位)。
  • 可以确认它现在已为我修复。

标签: html google-chrome geolocation


【解决方案1】:

我没有为“Returned error code 403”找到任何解决方案,但如果 google api 失败,我找到了一种获取当前位置的解决方案

 if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function (position) {
            current_location_lat = position.coords.latitude;
            current_location_lon = position.coords.longitude;
           }, function (error) {
//if error occurred by google api
              $.getJSON("http://ipinfo.io", function (ipinfo) {
                var latLong = ipinfo.loc.split(",");
                current_location_lat = latLong[0];
                current_location_lon = latLong[1];
                 });
            });

    } else {
        // Browser doesn't support Geolocation
        alert("Error: Your browser doesn\'t support geolocation");
    }

【讨论】:

    【解决方案2】:

    对于未来的查询:

    从 Chrome 50 开始,Chrome 不再支持使用 HTML5 Geolocation API 从通过非安全连接传递的页面获取用户位置。这意味着进行 Geolocation API 调用的页面必须通过 HTTPS 等安全上下文提供服务。

    https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only?hl=en

    如果您不使用 HTTPS,这将破坏您在 chrome 上的网络应用程序。

    【讨论】:

      【解决方案3】:

      一定是最新版 Chrome 的 bug,也出现在 Google Maps API 的页面:https://developers.google.com/maps/documentation/javascript/examples/map-geolocation

      希望它会尽快修复。

      已编辑:立即尝试,它可以工作:)

      【讨论】:

      • 出于调试目的,开发者工具中的传感器仿真仍然有效
      【解决方案4】:

      我在这里提交了错误票:https://productforums.google.com/forum/?utm_medium=email&utm_source=footer#!msg/chrome/q7B6gjCr1ps/Y9DEXPZ-_HYJ

      随时在此处发表评论、加注星标等。

      【讨论】:

        【解决方案5】:

        显然此 API 已被禁止从不安全位置访问see here

        【讨论】:

        • 是的,它应该按照链接文档的描述工作,如果您的服务器在 https 上发送页面
        • 我也刚升级到 https 还是不行
        猜你喜欢
        • 2023-03-22
        • 2011-09-05
        • 1970-01-01
        • 1970-01-01
        • 2020-08-08
        • 2013-05-27
        • 1970-01-01
        • 1970-01-01
        • 2012-08-04
        相关资源
        最近更新 更多