js geolocation but without prompting - possible?(js 地理定位但没有提示 - 可能吗?)
问题描述
是否可以在没有浏览器提示的情况下获取用户的地理位置?
Is it possible to get the geolocation of a user without the browser prompt?
这是来自 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() 的功能?
Is there any preventPrompt()-like function ?
推荐答案
不,你不能阻止提示,它是一个安全功能,因为不是每个用户都想分享它的位置.
No you cant prevent the prompt, its a security feature cause not every user wanna share its location.
来自 W3C 文档:
符合本规范的实现必须提供保护用户隐私的机制,这种机制应该确保不会通过此 API 提供任何位置信息未经用户明确许可.
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之类的服务.
But you can try to use a service like geoip in the error callback.
这篇关于js 地理定位但没有提示 - 可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:js 地理定位但没有提示 - 可能吗?
基础教程推荐
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
