佈局代碼以下git
<p id="demo">點擊這個按鈕,得到您的座標:</p>
<button onclick="getLocation()">試一下</button>佈局
js代碼以下this
var x=document.getElementById("demo");get
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;
}it