Witam serdecznie.
Nie wiem czy to dobry dział jednak chodzi o JavaScrupt. Mam problem z watchPosition w HTML 5.

Kod strony wygląda następująco:

  1. <!DOCTYPE html>
  2. <meta charset="utf-8" >
  3. <title>HTML5</title>
  4. <link rel="stylesheet" href="html5.css">
  5.  
  6. <script type="text/javascript">
  7.  
  8. function updateStatus(message) {
  9. document.getElementById("status").innerHTML = message;
  10. }
  11.  
  12. function success(position) {
  13. var map = new GMap2(document.getElementById("map_canvas"));
  14. map.setCenter(new GLatLng(position.coords.latitude, position.coords.longitude), 13);
  15. map.setUIToDefault();
  16. map.addOverlay(new GMarker(new GLatLng(position.coords.latitude, position.coords.longitude), 13));
  17. var geocoder = new GClientGeocoder();
  18. geocoder.getLocations(position.coords.latitude+','+position.coords.longitude, addAddressToMap);
  19.  
  20. document.getElementById('wysokoscgeograficzna').innerHTML = "Wysokosc to: " + position.coords.latitude + " stopni.";
  21. document.getElementById('dlugoscgeograficzna').innerHTML = "Szereokosc to: " + position.coords.longitude + " stopni.";
  22. document.getElementById('dokladnosc').innerHTML = "Dokladnosc to: " + position.coords.accuracy + " m.";
  23. document.getElementById('wysokoscnpm').innerHTML = "Wysokosc nad poziomem morza: " + postition.coords.altitude + " metrow n.p.m";
  24. document.getElementById('dokladnoscwysokosc').innerHTML = "Dokladnosc wysokosci: " + position.coords.altitudeAccuracy + " m.";
  25. document.getElementById('predkosc').innerHTML = "Predkosc: " + position.coords.speed + " km/h.";
  26. document.getElementById('kierunek').innerHTML = "Kierunek: " + position.coords.heading;
  27. }
  28.  
  29. function addAddressToMap(response)
  30. {
  31. if (!response || response.Status.code != 200) {
  32. alert("Sorry, we were unable to geocode that address");
  33. } else {
  34. place = response.Placemark[0];
  35. document.getElementById('adres').innerHTML = "Adres: " +place.address;
  36. }
  37. }
  38.  
  39. function initialize() {
  40. if (GBrowserIsCompatible()) {
  41. if (navigator.geolocation)
  42. {
  43. navigator.geolocation.getCurrentPosition(success, error,{'enableHighAccuracy':true});
  44. navigator.geolocation.watchPosition(success_watch, error_watch,{enableHighAccuracy: true, timeout: 20000, maximumAge: 0 });
  45. }
  46. else{
  47. alert('Geolokalizacja nie jest obslugiwana!');
  48. }
  49. }
  50. }
  51.  
  52. function success_watch(position_watch) {
  53.  
  54. document.getElementByid('watch_wysokoscgeograficzna').innerHTML = "Wysokosc to: :"; // + position_watch.coords.latitude + " stopni.";
  55. document.getElementByid('watch_dlugoscgeograficzna').innerHTML = "Szereokosc to: " + position_watch.coords.longitude + " stopni.";
  56. document.getElementByid('watch_dokladnosc').innerHTML = "Dokladnosc to: " + position_watch.coords.accuracy + " m.";
  57. document.getElementByid('watch_wysokoscnpm').innerHTML = "Wysokosc nad poziomem morza: " + postition.coords.altitude + " metrow n.p.m";
  58. document.getElementByid('watch_dokladnoscwysokosc').innerHTML = "Dokladnosc wysokosci: " + position_watch.coords.altitudeAccuracy + " m.";
  59. document.getElementByid('watch_predkosc').innerHTML = "Predkosc: " + position_watch.coords.speed + " km/h.";
  60. document.getElementByid('watch_kierunek').innerHTML = "Kierunek: " + position_watch.coords.heading;
  61. }
  62.  
  63. function error(err) {
  64. if(err.code==1)
  65. {
  66. updateStatus("User denied geolocation.");
  67. }
  68. else if(err.code==2)
  69. {
  70. updateStatus("Position unavailable.");
  71. }
  72. else if(err.code==3)
  73. {
  74. updateStatus("Timeout expired.");
  75. }
  76. else
  77. {
  78. updateStatus("ERROR:"+ err.message);
  79. }
  80. }
  81.  
  82. function error_watch(err_watch) {
  83. if(err_watch.code==1)
  84. {
  85. updateStatus("WatchPosition: User denied geolocation.");
  86. }
  87. else if(err_watch.code==2)
  88. {
  89. updateStatus("WatchPosition: Position unavailable.");
  90. }
  91. else if(err_watch.code==3)
  92. {
  93. updateStatus("WatchPosition: Timeout expired.");
  94. }
  95. else
  96. {
  97. updateStatus("WatchPosition: ERROR:"+ err_watch.message);
  98. }
  99. }
  100.  
  101.  
  102. </head>


W sekcji body mam:

  1. <body onLoad="initialize()">
  2. <section id="LOGO"></section>
  3. <section id="LOGO2"></section>
  4. <div id="container">
  5. <nav>
  6. <h3>Nawigacja (NAV):</h3>
  7. <a href="index.html">Strona Główna</a>
  8. <a href="canvas.html">Canvas</a>
  9. <a href="geo.html">Geolokalizacja</a>
  10. <a href="video.html">Audio/Video</a>
  11. <a href="communication.html">Komunikacja</a>
  12. <a href="socket.html">WebSocket</a>
  13. </nav>
  14. <section>
  15. <p>Standardowe informacje o lokalizacji:</p>
  16. <div id="map_canvas" style="width: 100%; height: 300px"></div>
  17. <p><label id="wysokoscgeograficzna"></label></p>
  18. <p><label id="dlugoscgeograficzna"></label></p>
  19. <p><label id="dokladnosc"></label></p>
  20. <p><label id="wysokoscnpm"></label></p>
  21. <p><label id="dokladnoscwysokosc"></label></p>
  22. <p><label id="predkosc"></label></p>
  23. <p><label id="kierunek"></label></p>
  24.  
  25. <p>Geolokalizaowanie poprzez watchPosition:</p>
  26.  
  27. <p><label id="status"></label></p>
  28. <p><label id="watch_wysokoscgeograficzna"></label></p>
  29. <p><label id="watch_dlugoscgeograficzna"></label></p>
  30. <p><label id="watch_dokladnosc"></label></p>
  31. <p><label id="watch_wysokoscnpm"></label></p>
  32. <p><label id="watch_dokladnoscwysokosc"></label></p>
  33. <p><label id="watch_predkosc"></label></p>
  34. <p><label id="watch_kierunek"></label></p>
  35.  
  36. </section>
  37. <aside>
  38. <h3>Aside</h3>
  39. <p> Prawa czesc strony odpowiedzialna w elemencie aside.</p>
  40. </aside>
  41. <footer>
  42. <h2>Stopka (footer)</h2>
  43. </footer>
  44. </div>
  45. </body>



Zasada działania:
Moim zadaniem jest stworzenie prostej strony internetowej w technologii HTML 5 z opcją geolokalizacji. Po rozpoczęciu ładowania elementu body zostaje uruchomiona funkcja initialize().
Zimlementowałem w niej funkcje getPosition, która działa bez żadnych zarzutów. Wyniki zostają wyświetlone poprzez google maps w elemencie div id="map_canvas". Nie ma żadnych problemów.
Natomiast co bym nie robił z watchPosition dostaję timeout. Obojętnie czy jest określony czas jaki ma aplikacja na zrealizowanie lokalizacji czy nie. Więc nie jest to kwestia czasu lokalizowania urządzenia. Kiedy zakomentuje funkcje getPosition jest to samo, więc odpada kwestia zbyt szybkiego wybrania ponownego lokalizowania i z tym związanych ograniczeń.

Bardzo będę wdzieczny za pomoc.