本文介绍了js地理位置但没有提示 - 可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能在没有浏览器提示的情况下获得用户的地理位置?
< ;脚本>
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
从等服务。
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:
But you can try to use a service like geoip in the error callback.
这篇关于js地理位置但没有提示 - 可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!