Skip to content

Commit 338b881

Browse files
better GPS position acquisition
1 parent 223f3ab commit 338b881

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

cache.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CACHE MANIFEST
2-
# version 90
2+
# version 91
33

44
# gogole maps files
55
http://maps.google.com/maps/api/js?v=3.10&sensor=false&key=AIzaSyCOqkcNey4CCyG4X0X5qxHAhCgD8g5DwXg

js/app.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var GPS_lat = null;
6161
var GPS_lon = null;
6262
var GPS_alt = null;
6363
var GPS_speed = null;
64-
var CHASE_enabled = false;
64+
var CHASE_enabled = null;
6565
var CHASE_listenerSent = false;
6666
var CHASE_timer = 0
6767
var callsign = "";
@@ -104,15 +104,27 @@ window.onchangeorientation = checkSize;
104104

105105
// functions
106106

107-
var positionUpdateHandle = function() {
107+
function positionUpdateError(error) {
108+
switch(error.code)
109+
{
110+
case error.PERMISSION_DENIED:
111+
alert("no permission to use your location");
112+
$('#sw_chasecar').click(); // turn off chase car
113+
break;
114+
default:
115+
break;
116+
}
117+
}
118+
119+
var positionUpdateHandle = function(position) {
108120
if(CHASE_enabled && !CHASE_listenerSent) {
109121
if(offline.get('opt_station')) {
110122
ChaseCar.putListenerInfo(callsign);
111123
CHASE_listenerSent = true;
112124
}
113125
}
114126

115-
navigator.geolocation.getCurrentPosition(function(position) {
127+
//navigator.geolocation.getCurrentPosition(function(position) {
116128
var lat = position.coords.latitude;
117129
var lon = position.coords.longitude;
118130
var alt = (position.coords.altitude) ? position.coords.altitude : 0;
@@ -141,10 +153,13 @@ var positionUpdateHandle = function() {
141153
}
142154

143155
// save position and update only if different is available
144-
if(GPS_lat != lat
156+
if(CHASE_timer < (new Date()).getTime()
157+
&& (
158+
GPS_lat != lat
145159
|| GPS_lon != lon
146160
|| GPS_alt != alt
147161
|| GPS_speed != speed)
162+
)
148163
{
149164
GPS_lat = lat;
150165
GPS_lon = lon;
@@ -155,6 +170,7 @@ var positionUpdateHandle = function() {
155170

156171
if(CHASE_enabled) {
157172
ChaseCar.updatePosition(callsign, position);
173+
CHASE_timer = (new Date()).getTime() + 15000;
158174
}
159175
}
160176
else { return; }
@@ -178,11 +194,13 @@ var positionUpdateHandle = function() {
178194
$('#cc_alt').text(alt + " m");
179195
$('#cc_accuracy').text(accuracy + " m");
180196
$('#cc_speed').text(speed + " m/s");
197+
/*
181198
},
182199
function() {
183200
// when there is no location
184201
$('#app_name b').html('mobile<br/>tracker');
185202
});
203+
*/
186204
}
187205

188206

@@ -297,7 +315,9 @@ $(window).ready(function() {
297315
field.removeAttr('disabled');
298316
e.removeClass('on').addClass('off');
299317

300-
CHASE_enabled = false;
318+
if(navigator.geolocation) navigator.geolocation.clearWatch(CHASE_enabled);
319+
CHASE_enabled = null;
320+
//CHASE_enabled = false;
301321

302322
// blue man reappers :)
303323
if(currentPosition && currentPosition.marker) currentPosition.marker.setVisible(true);
@@ -322,7 +342,9 @@ $(window).ready(function() {
322342
if(GPS_ts) {
323343
ChaseCar.updatePosition(callsign, { coords: { latitude: GPS_lat, longitude: GPS_lon, altitude: GPS_alt, speed: GPS_speed }});
324344
}
325-
CHASE_enabled = true;
345+
346+
if(navigator.geolocation) CHASE_enabled = navigator.geolocation.watchPosition(positionUpdateHandle, positionUpdateError);
347+
//CHASE_enabled = true;
326348

327349
// hide the blue man
328350
if(currentPosition && currentPosition.marker) currentPosition.marker.setVisible(false);
@@ -418,9 +440,10 @@ $(window).ready(function() {
418440
}
419441
});
420442

443+
navigator.geolocation.getCurrentPosition(positionUpdateHandle);
421444
// check for location update every 30sec
422-
setInterval(positionUpdateHandle, 30000);
445+
//setInterval(positionUpdateHandle, 30000);
423446
// immediatelly check for position
424-
positionUpdateHandle();
447+
//positionUpdateHandle();
425448
}
426449
});

0 commit comments

Comments
 (0)