Advertisement
WujaGoczlo

Untitled

Jan 24th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var watchID;
  2.  
  3.  
  4. function navigate() {
  5.     var options = {
  6.         frequency: 2000
  7.     };
  8.     watchID = navigator.compass.watchHeading(onSuccess1, onError1, options);
  9.  
  10. }
  11.  
  12.  
  13.  
  14.  
  15. function onSuccess1(heading) {
  16.     if(bestPosition == lastPostition)
  17.         alert("Jestes u celu");
  18.  
  19.     //var nav = azimuth(Position.coords.latitude,Position.coords.longitude,bestLat,bestLng);
  20.  
  21.  
  22.     var direction = Math.round(heading.magneticHeading);
  23.     alert(direction);
  24.     var angle = document.getElementById('heading');
  25.     angle.innerHTML = 'Heading:' + direction;
  26.  
  27.     $("#directionArrow").rotate(direction);
  28. };
  29.  
  30. function onError1(error) {
  31.     alert('CompassError: ' + error.code);
  32. };
  33.  
  34.  
  35. function azimuth(x1,y1,x2,y2) {
  36.     var x = x2-x1;
  37.     var y = y2-y1;
  38.     var result = Math.atan2(x,y)*200.0/Math.PI;
  39.     if(result<0)
  40.         result +=360.0;
  41.     return result;
  42. }
  43.  
  44.  
  45.  
  46.  
  47. $(document).on( "click", '#runCompass', function() {
  48.     if(bestPosition == null) {
  49.         setTimeout(function(){
  50.             actual_lat = Position.coords.latitude;
  51.             actual_long = Position.coords.longitude;
  52.             db_navigate.transaction(populateDB_searchNearestPoint, errorCB_nav, successCB);
  53.  
  54.         },1000);
  55.     }
  56.     setTimeout(function(){
  57.         navigate();
  58.     },3000);
  59. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement