@@ -355,89 +355,83 @@ var positionUpdateHandle = function(position) {
355355 }
356356 }
357357
358- //navigator.geolocation.getCurrentPosition(function(position) {
359- var lat = position . coords . latitude ;
360- var lon = position . coords . longitude ;
361- var alt = ( position . coords . altitude ) ? position . coords . altitude : 0 ;
362- var accuracy = ( position . coords . accuracy ) ? position . coords . accuracy : 0 ;
363- var speed = ( position . coords . speed ) ? position . coords . speed : 0 ;
364-
365- // constantly update 'last updated' field, and display friendly time since last update
366- if ( ! GPS_ts ) {
367- GPS_ts = parseInt ( position . timestamp / 1000 ) ;
368-
369- setInterval ( function ( ) {
370- var delta_ts = parseInt ( Date . now ( ) / 1000 ) - GPS_ts ;
371-
372- // generate friendly timestamp
373- var hours = Math . floor ( delta_ts / 3600 ) ;
374- var minutes = Math . floor ( delta_ts / 60 ) % 60 ;
375- var ts_str = ( delta_ts >= 60 ) ?
376- ( ( hours ) ?hours + 'h ' :'' ) +
377- ( ( minutes ) ?minutes + 'm' :'' ) +
378- ' ago'
379- : 'just now' ;
380- $ ( '#cc_timestamp' ) . text ( ts_str ) ;
381- } , 30000 ) ;
382-
383- $ ( '#cc_timestamp' ) . text ( 'just now' ) ;
384- }
358+ var lat = position . coords . latitude ;
359+ var lon = position . coords . longitude ;
360+ var alt = ( position . coords . altitude ) ? position . coords . altitude : 0 ;
361+ var accuracy = ( position . coords . accuracy ) ? position . coords . accuracy : 0 ;
362+ var speed = ( position . coords . speed ) ? position . coords . speed : 0 ;
363+
364+ // constantly update 'last updated' field, and display friendly time since last update
365+ if ( ! GPS_ts ) {
366+ GPS_ts = parseInt ( position . timestamp / 1000 ) ;
367+
368+ setInterval ( function ( ) {
369+ var delta_ts = parseInt ( Date . now ( ) / 1000 ) - GPS_ts ;
370+
371+ // generate friendly timestamp
372+ var hours = Math . floor ( delta_ts / 3600 ) ;
373+ var minutes = Math . floor ( delta_ts / 60 ) % 60 ;
374+ var ts_str = ( delta_ts >= 60 ) ?
375+ ( ( hours ) ?hours + 'h ' :'' ) +
376+ ( ( minutes ) ?minutes + 'm' :'' ) +
377+ ' ago'
378+ : 'just now' ;
379+ $ ( '#cc_timestamp' ) . text ( ts_str ) ;
380+ } , 30000 ) ;
381+
382+ $ ( '#cc_timestamp' ) . text ( 'just now' ) ;
383+ }
385384
386- // save position and update only if different is available
387- if ( CHASE_timer < ( new Date ( ) ) . getTime ( ) &&
388- (
389- GPS_lat != lat ||
390- GPS_lon != lon ||
391- GPS_alt != alt ||
392- GPS_speed != speed
393- )
385+ // save position and update only if different is available
386+ if ( CHASE_timer < ( new Date ( ) ) . getTime ( ) &&
387+ (
388+ GPS_lat != lat ||
389+ GPS_lon != lon ||
390+ GPS_alt != alt ||
391+ GPS_speed != speed
394392 )
395- {
396- GPS_lat = lat ;
397- GPS_lon = lon ;
398- GPS_alt = alt ;
399- GPS_speed = speed ;
400- GPS_ts = parseInt ( position . timestamp / 1000 ) ;
401- $ ( '#cc_timestamp' ) . text ( 'just now' ) ;
402-
403- // update look angles once we get position
404- if ( follow_vehicle !== null && vehicles [ follow_vehicle ] !== undefined ) {
405- update_lookangles ( follow_vehicle ) ;
406- }
393+ )
394+ {
395+ GPS_lat = lat ;
396+ GPS_lon = lon ;
397+ GPS_alt = alt ;
398+ GPS_speed = speed ;
399+ GPS_ts = parseInt ( position . timestamp / 1000 ) ;
400+ $ ( '#cc_timestamp' ) . text ( 'just now' ) ;
401+
402+ // update look angles once we get position
403+ if ( follow_vehicle !== null && vehicles [ follow_vehicle ] !== undefined ) {
404+ update_lookangles ( follow_vehicle ) ;
405+ }
407406
408- if ( CHASE_enabled ) {
409- ChaseCar . updatePosition ( callsign , position ) ;
410- CHASE_timer = ( new Date ( ) ) . getTime ( ) + 15000 ;
411- }
407+ if ( CHASE_enabled ) {
408+ ChaseCar . updatePosition ( callsign , position ) ;
409+ CHASE_timer = ( new Date ( ) ) . getTime ( ) + 15000 ;
412410 }
413- else { return ; }
414-
415- // add/update marker on the map (sondehub.js)
416- updateCurrentPosition ( lat , lon ) ;
417-
418- // round the coordinates
419- lat = parseInt ( lat * 10000 ) / 10000 ; // 4 decimal places (11m accuracy at equator)
420- lon = parseInt ( lon * 10000 ) / 10000 ; // 4 decimal places
421- speed = parseInt ( speed * 10 ) / 10 ; // 1 decimal place
422- accuracy = parseInt ( accuracy ) ;
423- alt = parseInt ( alt ) ;
424-
425- // dispaly them in the top right corner
426- $ ( '#app_name b' ) . html ( lat + '<br/>' + lon ) ;
427-
428- // update chase car interface
429- $ ( '#cc_lat' ) . text ( lat ) ;
430- $ ( '#cc_lon' ) . text ( lon ) ;
431- $ ( '#cc_alt' ) . text ( alt + " m" ) ;
432- $ ( '#cc_accuracy' ) . text ( accuracy + " m" ) ;
433- $ ( '#cc_speed' ) . text ( speed + " m/s" ) ;
434- /*
435- },
436- function() {
437- // when there is no location
438- $('#app_name b').html('mobile<br/>tracker');
439- });
440- */
411+ }
412+
413+
414+ // add/update marker on the map (sondehub.js)
415+ updateCurrentPosition ( lat , lon ) ;
416+
417+ // round the coordinates
418+ lat = parseInt ( lat * 10000 ) / 10000 ; // 4 decimal places (11m accuracy at equator)
419+ lon = parseInt ( lon * 10000 ) / 10000 ; // 4 decimal places
420+ speed = parseInt ( speed * 10 ) / 10 ; // 1 decimal place
421+ accuracy = parseInt ( accuracy ) ;
422+ alt = parseInt ( alt ) ;
423+
424+ // dispaly them in the top right corner
425+ $ ( '#app_name b' ) . html ( lat + '<br/>' + lon ) ;
426+
427+ // update chase car interface
428+ $ ( '#cc_lat' ) . text ( lat ) ;
429+ $ ( '#cc_lon' ) . text ( lon ) ;
430+ $ ( '#cc_alt' ) . text ( alt + " m" ) ;
431+ $ ( '#cc_accuracy' ) . text ( accuracy + " m" ) ;
432+ $ ( '#cc_speed' ) . text ( speed + " m/s" ) ;
433+
434+
441435} ;
442436
443437var twoZeroPad = function ( n ) {
@@ -703,7 +697,6 @@ $(window).ready(function() {
703697 field . removeAttr ( 'disabled' ) ;
704698 e . removeClass ( 'on' ) . addClass ( 'off' ) ;
705699
706- if ( navigator . geolocation ) navigator . geolocation . clearWatch ( CHASE_enabled ) ;
707700 CHASE_enabled = null ;
708701 //CHASE_enabled = false;
709702
@@ -731,8 +724,7 @@ $(window).ready(function() {
731724 ChaseCar . updatePosition ( callsign , { coords : { latitude : GPS_lat , longitude : GPS_lon , altitude : GPS_alt , speed : GPS_speed } } ) ;
732725 }
733726
734- if ( navigator . geolocation ) CHASE_enabled = navigator . geolocation . watchPosition ( positionUpdateHandle , positionUpdateError ) ;
735- //CHASE_enabled = true;
727+ CHASE_enabled = true ;
736728
737729 // hide the blue man
738730 if ( currentPosition && currentPosition . marker ) map . removeLayer ( currentPosition . marker ) ;
@@ -986,10 +978,7 @@ $(window).ready(function() {
986978 } ) ;
987979
988980 navigator . geolocation . getCurrentPosition ( positionUpdateHandle ) ;
989- // check for location update every 30sec
990- //setInterval(positionUpdateHandle, 30000);
991- // immediatelly check for position
992- //positionUpdateHandle();
981+ if ( navigator . geolocation ) navigator . geolocation . watchPosition ( positionUpdateHandle , positionUpdateError ) ;
993982 }
994983
995984 // weather feature
0 commit comments