I have read the same problem many times here and fixed the most repeated solutions and added the error handler like mentioned on the w3c specification but it gives me no exceptions or errors and no results. I don't know what I should do?
This is the complete code I have written!
<!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>