Advertisement
Guest User

Untitled

a guest
May 18th, 2016
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. <!DOCTYPE html >
  2. <head>
  3. <meta http-equiv="cache-control" content="no-cache">
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5. <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  6. <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
  7. <title>TrackMe by BrK 2016</title>
  8. <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBYSMqIzNgDh7oY-HnMSGxEr2ow6S-K9rE&libraries=geometry"
  9. type="text/javascript"></script>
  10. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
  11.  
  12. <style type="text/css">
  13. html, body, #map_canvas {
  14. height: 100%;
  15. width: 100%;
  16. margin: 0px;
  17. }
  18.  
  19. #map_canvas {
  20. position: relative;
  21. }
  22.  
  23. .angular-google-map-container {
  24. position: absolute;
  25. top: 0;
  26. bottom: 0;
  27. right: 0;
  28. left: 0;
  29. }
  30. </style>
  31.  
  32.  
  33.  
  34. <script type="text/javascript">
  35. //<![CDATA[
  36. <?php
  37. // get the date from the url parameter
  38. $filename = "data/" . $_GET['date'] . ".txt";
  39.  
  40. //setInterval(processData(data), 10000);
  41. ?>
  42.  
  43. // blue and red marker icons
  44. var customIcons = {
  45. bluePoint: {
  46. icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png'
  47. },
  48. redPoint: {
  49. icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png'
  50. }
  51. };
  52.  
  53. // global google map object
  54. var map;
  55. var path;
  56.  
  57. $(document).ready(function()
  58. {
  59. // initialise the map
  60. map = new google.maps.Map(document.getElementById('map'), {
  61. center: {lat: 48.251034, lng: 14.289567},
  62. zoom: 11
  63. });
  64.  
  65.  
  66. // create a path to show when the car has been
  67. path = new google.maps.Polyline({
  68. map: map,
  69. strokeColor: "#3333FF",
  70. strokeOpacity: 0.5,
  71. strokeWeight: 6
  72. });
  73.  
  74. // retrieve the data and set callback function
  75. $.ajax(
  76. {
  77. type: "GET",
  78. url: "<?php echo $filename ?>",
  79. dataType: "text",
  80. success: function(data) {processData(data);}
  81. });
  82.  
  83. setInterval(function() {
  84. $.ajax(
  85. {
  86. type: "GET",
  87. url: "<?php echo $filename ?>",
  88. dataType: "text",
  89. cache: false,
  90. success: function(data) {processData(data);}
  91. });
  92.  
  93. }, 5000);
  94. });
  95.  
  96.  
  97.  
  98. function processData(allText)
  99. {
  100. // split into the lines of data
  101. var allTextLines = allText.split(/\r\n|\n/);
  102. var lines = [];
  103. var coords = [];
  104.  
  105. for (var i=0; i<allTextLines.length; i++)
  106. {
  107. // split the comma seperated values
  108. var data = allTextLines[i].split(',');
  109.  
  110. if (data.length >= 3)
  111. {
  112. // create the point object
  113. var infoWindow = new google.maps.InfoWindow;
  114.  
  115. // set the position from the data
  116. var point = new google.maps.LatLng(
  117. parseFloat(data[2]),
  118. parseFloat(data[1]));
  119.  
  120. coords.push(point);
  121.  
  122. var distance = google.maps.geometry.spherical.computeLength(coords);
  123.  
  124. //convert to miles
  125. var miles = Math.round(distance/1609 * 100) / 100;
  126. //var km = (miles / 0.62137) / 1000;
  127. var html = "<b>Time: " + data[0] + "<br/>Distance: " + miles + " Miles"; // this is the timestamp
  128. //"<b>" + name + "</b> <br/>" + address;
  129. var icon = {};
  130.  
  131. if ( i == ( allTextLines.length - 2 ) ) // this is 2 because the last line is empty
  132. {
  133. // make the last entry a red marker
  134. icon = customIcons["redPoint"] || {};
  135. }
  136. else
  137. {
  138. icon = customIcons["bluePoint"] || {};
  139. }
  140.  
  141. // create the marker
  142. var marker = new google.maps.Marker(
  143. {
  144. map: map,
  145. position: point,
  146. icon: icon.icon,
  147. });
  148.  
  149. // create the info window that displays the timestamp
  150. bindInfoWindow(marker, map, infoWindow, html);
  151. }
  152. }
  153.  
  154. // add the coords to the path
  155. path.setPath(coords);
  156. }
  157.  
  158. function bindInfoWindow(marker, map, infoWindow, html)
  159. {
  160. google.maps.event.addListener(marker, 'click', function() {
  161. infoWindow.setContent(html);
  162. infoWindow.open(map, marker);
  163. });
  164. }
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172. //]]>
  173. </script>
  174.  
  175. </head>
  176. <body>
  177. <div id="map" style="width: 100%; height: 100%"></div>
  178. </body>
  179.  
  180. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement