var x=document.getElementById("demo"); function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else{x.innerHTML="您的浏览器不支持!";} } function showPosition(position) { x.innerHTML="纬度: " + position.coords.latitude + "<br />经度: " + position.coords.longitude; }