javascript-js地理位置定位但没有提示-可能吗?

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

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>

是否有任何类似于preventPrompt()的函数?

解决方法:

不,您无法阻止该提示,它的安全功能导致并非每个用户都希望共享其位置.

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.

但是您可以尝试在错误回调中使用诸如geoip之类的服务.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。