改编自 HTML5 演示
Test passed on 9800 OS 6.0
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
</head>
<body>
<span class="js">JS</span>
<h1>地理位置 - Geolocation</h1>
<div class="slide current">
<section>
<button id="see_position">显示你的位置</button>
<br/>
<input type="text" id="LAT_value"></input>
<br/>
<input type="text" id="LNG_value"></input>
<div id="content" style="height: 280px;"></div>
<script>
document.getElementById('see_position').addEventListener('click', function() {
document.getElementById("LAT_value").value="getting location...";
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
// also monitor position as it changes
navigator.geolocation.watchPosition(showPosition);
} else {
console.log("no geolocation support");
}
function showPosition(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
document.getElementById("LAT_value").value="LAT: " + lat;
document.getElementById("LNG_value").value="LNG: " + lng;
}
}, false);
</script>
</section>
</div>
</body>
</html>