问题描述
我有一个window.navigator的问题,当我运行下面的代码作为本地html文件时,我得到错误代码1,User denied Geolocation pre> navigator.geolocation.getCurrentPosition(function(position){
console.log(position);
},function(positionError){
console。 log(positionError);
});
输出来自错误函数,positionError包含:
code:1
message:User denied Geolocation
如果包含的HTML是从某个服务器提供的,则不会发生这种情况。
这是预期的吗?有没有从本地HTML使用导航器的方法?我试图写一些移动应用程序,但也尽可能避免网络。
谢谢。
如果您使用的是chrome,请查看下面的答案:
它出现这是文件
协议的安全限制。看起来你需要从服务器本地托管它。
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);
});
The output is coming from the error function, positionError contains:
code: 1
message: "User denied Geolocation"
This does not happen if the containing html is served from some server.
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.
thanks.
If you are using chrome, please have a look at the answer below:
HTML 5 Geo Location Prompt in Chrome
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导航器“用户拒绝地理定位”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!