html5獲取當前手機位置的精度維度
阿新 • • 發佈:2017-10-17
onclick navigator doc document etl oca on() pos eol
布局代碼如下
<p id="demo">點擊這個按鈕,獲得您的坐標:</p>
<button onclick="getLocation()">試一下</button>
js代碼如下
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;
}
html5獲取當前手機位置的精度維度