0

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>
hippietrail
  • 13,703
  • 15
  • 87
  • 133
Mustafa ELnagar
  • 412
  • 3
  • 11
  • 23

1 Answers1

0

You are using input controls. Try setting the value instead of the innerHTML.

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").value = latitude;
    document.getElementById("longitude").value = longitude;
    document.getElementById("accuracy").value = accuracy;
    document.getElementById("timestamp").value = timestamp; 
      // sanity test... don't calculate distance if accuracy 
    // value too large 
    if (accuracy >= 500) { 
        updateStatus("Need more accurate values to calculate distance."); 
        return; 
    }
} 
Maurice
  • 27,324
  • 5
  • 46
  • 61
  • thanks alot @Maurice , I rewrite it and also doesn't make sense for me . the problem that the browser doesn't process the `position.coords.latitude` I retested the maximum age and time out and still exists ! I don't know what I shall do ! – Mustafa ELnagar Jul 10 '12 at 09:17
  • first check.your browser if the request return a value , test it with this demo, html5demos/geo – Mustafa ELnagar Aug 31 '12 at 16:22
  • You can use watchposition() instead of the updateposition , it makes a loop of requesting the coords , i used it usually , Good luck :-) – Mustafa ELnagar Aug 31 '12 at 16:26