Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. /*jslint sloppy:true, browser:true, devel:true, white:true, vars:true, eqeq:true, nomen:true, unparam:true */
  2. /*global intel, google, Marker, device */
  3.  
  4.  
  5. //calculates distance between two points in km's
  6. function calcDistance(p1, p2) {
  7. return (google.maps.geometry.spherical.computeDistanceBetween(p1, p2) / 1000).toFixed(2);
  8. }
  9.  
  10.  
  11. var _map = null;
  12. var _seconds = 30;
  13. var _llbounds = null;
  14. var myLatLng;
  15. var oldLatLng = "";
  16. var boolTripTrack = true;
  17. var dis;
  18. //Create the google Maps and LatLng object
  19.  
  20. function drawMap() {
  21. //Creates a new google maps object
  22. var latlng = new google.maps.LatLng(currentLatitude, currentLongitude);
  23. myLatLng = latlng;
  24. var mapOptions = {
  25. center: latlng,
  26. zoom: 10,
  27. mapTypeId: google.maps.MapTypeId.ROADMAP,
  28. zoomControl: true,
  29. zoomControlOptions: {
  30. style: google.maps.ZoomControlStyle.SMALL,
  31. position: google.maps.ControlPosition.LEFT_TOP
  32. }
  33. };
  34. if (boolTripTrack === true) {
  35. if(google.maps){
  36. _map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
  37. }
  38.  
  39. else {
  40. alert("Unable to display map.");
  41. }
  42. }
  43. }
  44. //40.7655,-73.97204 = NYC
  45. var currentLatitude = "51.893969";
  46. var currentLongitude = "-8.467430";
  47.  
  48. var clue1Lat = "51.893971";
  49. var clue1Long = "-8.467012";
  50.  
  51. var clue2Lat = "51.899537";
  52. var clue2Long = "-8.470992";
  53. var options = {
  54. timeout: 10000,
  55. maximumAge: 11000,
  56. enableHighAccuracy: true
  57. };
  58. //Success callback
  59. var suc = function(p) {
  60. console.log("geolocation success", 4);
  61. //Draws the map initially
  62. var clue1LatLng = new google.maps.LatLng(clue1Lat, clue1Long);
  63. var clue2LatLng = new google.maps.LatLng(clue2Lat, clue2Long);
  64. if (_map === null) {
  65. var currentLatitude = p.coords.latitude;
  66. var currentLongitude = p.coords.longitude;
  67.  
  68. drawMap();
  69. } else {
  70. myLatLng = new google.maps.LatLng(p.coords.latitude, p.coords.longitude);
  71. dis = calcDistance(myLatLng, clue2LatLng);
  72. clue1LatLng = new google.maps.LatLng(clue1Lat, clue1Long);
  73. clue2LatLng = new google.maps.LatLng(clue2Lat, clue2Long);
  74. }
  75. //Creates a new google maps marker object for using with the pins
  76.  
  77. if ((myLatLng.toString().localeCompare(oldLatLng.toString())) !== 0) {
  78. //marker.setMap(null);
  79. //Create a new map marker
  80.  
  81. var Marker = new google.maps.Marker({
  82. position: myLatLng,
  83. map: _map
  84. });
  85. var Marker1 = new google.maps.Marker({
  86. position: clue1LatLng,
  87. map: _map
  88. });
  89. var Marker2 = new google.maps.Marker({
  90. position: clue2LatLng,
  91. map: _map
  92. });
  93. if (_llbounds === null) {
  94. //Create the rectangle in geographical coordinates
  95. _llbounds = new google.maps.LatLngBounds(new google.maps.LatLng(p.coords.latitude, p.coords.longitude)); //original
  96. } else {
  97. //Extends geographical coordinates rectangle to cover current position
  98. _llbounds.extend(myLatLng);
  99. }
  100. //Sets the viewport to contain the given bounds & triggers the "zoom_changed" event
  101. _map.fitBounds(_llbounds);
  102. }
  103. oldLatLng = myLatLng;
  104. };
  105. var fail = function() {
  106. console.log("Geolocation failed. \nPlease enable GPS in Settings.", 1);
  107. };
  108. var getLocation = function() {
  109. console.log("in getLocation", 4);
  110. };
  111. //Execute when the DOM loads
  112.  
  113. function onDeviceReady() {
  114. try {
  115. if (navigator.geolocation !== null) {
  116. document.getElementById("map_canvas").style.height = screen.height + "px";
  117. navigator.geolocation.watchPosition(suc, fail, options);
  118. }
  119. else {
  120. alert("navigator.geolocation == null");
  121. }
  122. } catch (e) {
  123. alert(e.message);
  124. }
  125.  
  126. try {
  127. //hide splash screen
  128. navigator.splashscreen.hide(); 
  129. } catch (e) {}
  130. }
  131. document.addEventListener("deviceready", onDeviceReady, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement