Javascript 如何在Chrome Mobile中获取更新的经纬度
我想使用javascript创建位置跟踪web应用程序 此web应用程序每3秒更新一次纬度和经度值 这是我的密码Javascript 如何在Chrome Mobile中获取更新的经纬度,javascript,location,latitude-longitude,Javascript,Location,Latitude Longitude,我想使用javascript创建位置跟踪web应用程序 此web应用程序每3秒更新一次纬度和经度值 这是我的密码 <p>Get Latitude and Longitude each 3 sec</p> <p id="demo"></p> <script> var x = document.getElementById("demo"); setInterval(getLocation, 3
<p>Get Latitude and Longitude each 3 sec</p>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
setInterval(getLocation, 3000);
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
var node = document.createElement("div");
node.innerHTML = "Latitude: " + position.coords.latitude + "<br>" + "Longitude: " + position.coords.longitude+ "<br><br>";
document.getElementById("demo").appendChild(node);
}
</script>
每3秒获取一次纬度和经度
var x=document.getElementById(“演示”);
设置间隔(getLocation,3000);
函数getLocation(){
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(showPosition);
}否则{
x、 innerHTML=“此浏览器不支持地理位置。”;
}
}
功能显示位置(位置){
var节点=document.createElement(“div”);
node.innerHTML=“纬度:”+position.coords.Latitude+”
“+”经度:“+position.coords.Longitude+”
”;
document.getElementById(“demo”).appendChild(节点);
}
但是值是相同的并且是固定的
是否有可能获得保持更新的纬度和经度值???
多谢各位