如何使用javascript地理位置更改布尔值
我想知道是否可以使用Javascript地理位置来更改变量 如果我在加利福尼亚,那么我的Javascript地理位置代码将返回true。但如果我在其他地方,它将返回false如何使用javascript地理位置更改布尔值,javascript,geolocation,Javascript,Geolocation,我想知道是否可以使用Javascript地理位置来更改变量 如果我在加利福尼亚,那么我的Javascript地理位置代码将返回true。但如果我在其他地方,它将返回false var x = document.getElementById("demo"); function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition
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;
}
var x=document.getElementById(“演示”);
函数getLocation(){
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(showPosition);
}否则{
x、 innerHTML=“此浏览器不支持地理位置。”;
}
}
功能显示位置(位置){
x、 innerHTML=“Latitude:”+position.coords.Latitude+”
经度:“+position.coords.Longitude;
}
有什么办法可以做到这一点吗?是的,当然有办法。怎么可能?当然。但是,就个人而言,我会根据用户的时区得到
true
/false
。更简单,无需API调用。可以肯定的是@Scott Marcus可能会重复这一点。