Origin 无权使用地理定位服务——即使是通过 HTTPS [英] Origin does not have permission to use Geolocation service -- even over HTTPS

查看:197
本文介绍了Origin 无权使用地理定位服务——即使是通过 HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过 HTTPS 使用 HTML5 地理定位的网页.它在桌面浏览器上工作正常.但是,在 iOS Safari 上,我收到Origin 无权使用地理定位服务"的错误消息.我确保页面上的所有内容都通过 HTTPS 加载——每个图像、每个脚本和所有其他资产都在 Chrome 开发工具中显示 HTTPS.尽管如此,地理定位会返回错误.

I have a web page that uses HTML5 geolocation over HTTPS. It works a-okay on desktop browsers. On iOS Safari, however, I get the error that "Origin does not have permission to use Geolocation service". I have ensured that everything on the page loads via HTTPS -- every image, every script, and all other assets are showing HTTPS in Chrome dev tools. Nonetheless, geolocation returns the error.

这是我的一些 JavaScript:

Here's some of my JavaScript:

if ("geolocation" in navigator) {
    navigator.geolocation.getCurrentPosition(function (position) {
        // Do stuff with the geo data...
    }, function(error) {
        // I always end up here on iOS Safari.
        alert(error.code + ": " + error.message);
    });
} 
else {
    $("#search-results").append("Location is unavailable in this browser.");
}

我错过了什么?

更多信息:我刚刚从这个W3 Schools 示例,它在我的 iOS Safari 中完美运行,并将其粘贴到我的网站上.这没用.我仍然没有收到允许在我的网站上进行地理定位的提示.我已清除浏览器缓存并在设置"中重置位置警告无济于事.

More info: I just grabbed the code from this W3 Schools example, which works perfectly in my iOS Safari, and pasted it on my site. It did not work. I still receive no prompt to allow geolocation on my site. I've cleared browser cache and reset location warnings in Settings to no avail.

推荐答案

我遇到了同样的问题,这是因为 Chrome(和 Safari)中 Golocation API 的新标准:

I had the same problem and it is because of new standards for the Golocation API in Chrome (and Safari):

Chrome 不再支持使用 HTML5 Geolocation API 从非安全连接提供的页面获取用户位置.

Chrome no longer supports obtaining the user's location using the HTML5 Geolocation API from pages delivered by non-secure connections.

唯一的解决方案是从 HTTPS 托管并删除来自第三方的所有 HTTP 请求.在开发者模式下检查您的网络选项卡以过滤掉 HTTP 调用,这也包括图像(这对我来说是个问题).

The only solution is to host from HTTPS and remove all HTTP requests from third parties. Check your network tab in developer mode to filter out HTTP calls, this also includes images (which was the trouble in my case).

您可以在此处阅读更多信息:Geolocation API已从 Unsecured Origins 中删除.

You can read more here: Geolocation API Removed from Unsecured Origins.

这篇关于Origin 无权使用地理定位服务——即使是通过 HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆