improved auto update of location
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 28 May 2013 05:23:38 +0000 (05:23 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 28 May 2013 05:23:38 +0000 (05:23 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1290 01035d8c-6547-0410-b346-abe4f91aad63

foxy/foxy.html

index e38b58f3b5ec54053a55f18e11c57e4a2b2965ff..09a050b2d1772c46fd81eea3d85c796a3e6c4be2 100644 (file)
@@ -45,7 +45,7 @@
   var debug_enable  = 1;  
   var known_location = true;
   var bearing = 0.0;
-
+  
   var bearings  = []; // database of bearings we keep in memory
                       // mirrors bearings.txt
 
@@ -54,6 +54,7 @@
   var geolng = 0;
   var hasCompass;
   var currentHeading;
+  var posMarker;
 
   //
   // Initialisation ----------------------------------------------------------------
 
   function initialize() {
 
-    // if geolocation supported get our location 
+    // if geolocation supported get our initial location 
 
-    if(navigator.geolocation) {
+     if(navigator.geolocation) {
       geolocationSupport = true;
+
       navigator.geolocation.getCurrentPosition(function(position) {
+        log("getCurrentPosition");
         lat = geolat = position.coords.latitude;
         lng = geolng = position.coords.longitude;
+
         continueInit();
       }, function() {
-        geolocationSupport = false;
         continueInit();
-      });
+      }, {timeout:5});
     }
   }
 
     
     document.control_panel.debug_enable.checked = debug_enable;
 
+    if (geolocationSupport) {
+      posMarker = new google.maps.Marker(
+        {position: myLatlng, 
+        map: map});
+      navigator.geolocation.watchPosition(showPosition);
+    }
+
     // read from bearings.txt database text file on server and init map
     
     downloadUrl("/cgi-bin/getbearings.cgi", loadBearings);
     }
   }
 
+  // this function calls itself every update_time seconds
+  // used for peridoic updates (polling) of network stats
+
+  function showPosition(position) {
+    lat = geolat = position.coords.latitude;
+    lng = geolng = position.coords.longitude;
+    log("showPosition lat=" + lat + " lng=" + lng);                                      
+
+    posMarker.setPosition( new google.maps.LatLng( lat, lng ) );
+  }
 
   //
   // GUI Call Backs  ----------------------------------------------------------------
       {position: location, 
        map: map});
 
-    // idea: might be useful fore "new" bearing indicator
+    // idea: might be useful for "new" bearing indicator
     // if (isNewBearing) {
     //  newMarker.setAnimation(google.maps.Animation.BOUNCE);
     //}
       lat = geolat;
       lng = geolng;
       myzoom = 12;
-      log("no cookie, lat = " + lat + "lng = " + lng);
+      log("no cookie, lat = " + lat + " lng = " + lng);
     }
 
   }