js地理位置但没有提示 - 可能吗? [英] js geolocation but without prompting - possible?

查看:129
本文介绍了js地理位置但没有提示 - 可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在没有浏览器提示的情况下获得用户的地理位置?



这是W3的代码示例

 < ;脚本> 
var x = document.getElementById(demo)

函数getLocation(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(showPosition );
} else {
x.innerHTML =此浏览器不支持地理定位。;}
}
函数showPosition(position){
x.innerHTML = 纬度:+ position.coords.latitude +
< br>经度:+ position.coords.longitude;
}
< / script>

有没有 preventPrompt() --like功能?

解决方案

$不能阻止提示,其安全功能不会导致每个用户都想分享它的位置。 b
$ b

W3C文档
$ b


本规范的一致性实现必须提供一个
机制来保护用户的隐私,这种机制应该是
确保在未经用户明确许可的情况下,通过此API
无法获得位置信息。


但您可以尝试在错误回调中使用 geoip 等服务。


Is it possible to get the geolocation of a user without the browser prompt?

Here's the code sample from W3

<script>
   var x = document.getElementById("demo")

   function getLocation(){
     if(navigator.geolocation){
       navigator.geolocation.getCurrentPosition(showPosition);
     } else {
       x.innerHTML="Geolocation is not supported by this browser.";}
     }
     function showPosition(position){
       x.innerHTML="Latitude: " + position.coords.latitude + 
       "<br>Longitude: " + position.coords.longitude;   
     }
</script>

Is there any preventPrompt()-like function ?

解决方案

No you cant prevent the prompt, its a security feature cause not every user wanna share its location.

From the W3C docs:

A conforming implementation of this specification must provide a mechanism that protects the user's privacy and this mechanism should ensure that no location information is made available through this API without the user's express permission.

But you can try to use a service like geoip in the error callback.

这篇关于js地理位置但没有提示 - 可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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