我在这里多次阅读了相同的问题,并修复了最重复的解决方案,并添加了 w3c 规范中提到的错误处理程序,但它没有给我任何异常或错误,也没有结果。我不知道我该怎么办?
这是我写的完整代码!
<!DOCTYPE HTML>
<html>
<head>
<title> HTML5 Egypt User Group - Demos</title>
<script src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
var lastLat;
var lastLong;
function updateStatus(message) {
document.getElementById("status").innerHTML = message;
}
function loadDemo() {
if(navigator.geolocation) {
updateStatus("W3C Geolocation is supported in your browser.");
navigator.geolocation.watchPosition(updateLocation,
handleLocationError,
{maximumAge:20000});
}
}
window.addEventListener("load", loadDemo, true);
function handleLocationError(error) {
switch (error.code) {
case 0:
updateStatus("There was an error while retrieving your location: " +
error.message);
break;
case 1:
updateStatus("The user prevented this page from retrieving a location.");
break;
case 2:
updateStatus("The browser was unable to determine your location: " +
error.message);
break;
case 3:
updateStatus("The browser timed out before retrieving the location.");
break;
}
}
function updateLocation(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var accuracy = position.coords.accuracy;
var timestamp = position.timestamp;
document.getElementById("latitude").innerHTML = latitude;
document.getElementById("longitude").innerHTML = longitude;
document.getElementById("accuracy").innerHTML = accuracy;
document.getElementById("timestamp").innerHTML = timestamp;
// sanity test... don't calculate distance if accuracy
// value too large
if (accuracy >= 500) {
updateStatus("Need more accurate values to calculate distance.");
return;
}
}
</script>
</head>
<body>
<button onclick="loadDemo()"> loadDemo()</button>
<input type="text" value="latitude here" id="latitude" />
<input type="text" value="latitude here" id="latitude" />
<input type="text" value="accuracy here" id="accuracy" />
<input type="text" value="timestamp here" id="timestamp" />
<input type="text" value="status here" id="status" />
<span> By Mustafa Adel<span>
</body>
</html>