html navigator quot;User denied Geolocationquot;(html 导航器“用户拒绝地理位置)
问题描述
我在使用 window.navigator 时遇到问题,每当我将以下代码作为本地 html 文件运行时,我都会收到错误代码 1用户拒绝地理位置":
I have an issue with window.navigator, I'm getting error code 1, "User denied Geolocation" whenever I run the following code as a local html file:
navigator.geolocation.getCurrentPosition(function(position) {
console.log(position);
}, function(positionError) {
console.log(positionError);
});
输出来自误差函数,positionError 包含:
The output is coming from the error function, positionError contains:
code: 1
message: "User denied Geolocation"
如果包含的 html 是从某个服务器提供的,则不会发生这种情况.
This does not happen if the containing html is served from some server.
这是预期的吗?有没有办法从本地 html 使用导航器?我正在尝试编写一些移动应用程序,但也尽可能避免使用网络.
Is this expected? Is there some way to use navigator from a local html? I am trying to write some mobile app, but am also trying to avoid network whenever possible.
谢谢.
推荐答案
如果你用的是chrome,请看下面的答案:
If you are using chrome, please have a look at the answer below:
Chrome 中的 HTML 5 地理位置提示
这似乎是 file
协议的安全限制.看起来您需要从服务器本地托管它.
It appears this is a security restriction for the file
protocol. Looks like you are going to need to host it locally from a server.
这篇关于html 导航器“用户拒绝地理位置"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:html 导航器“用户拒绝地理位置"


基础教程推荐
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01