Region code biasing (US)


SUBMITTED BY: jlolk3r

DATE: Feb. 17, 2016, 2:53 a.m.

FORMAT: HTML

SIZE: 4.5 kB

HITS: 1268

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
  5. <meta charset="utf-8">
  6. <title>Waypoints in directions</title>
  7. <style>
  8. html, body {
  9. height: 100%;
  10. margin: 0;
  11. padding: 0;
  12. }
  13. #map {
  14. height: 100%;
  15. float: left;
  16. width: 70%;
  17. height: 100%;
  18. }
  19. #right-panel {
  20. font-family: 'Roboto','sans-serif';
  21. line-height: 30px;
  22. padding-left: 10px;
  23. }
  24. #right-panel select, #right-panel input {
  25. font-size: 15px;
  26. }
  27. #right-panel select {
  28. width: 100%;
  29. }
  30. #right-panel i {
  31. font-size: 12px;
  32. }
  33. #right-panel {
  34. margin: 20px;
  35. border-width: 2px;
  36. width: 20%;
  37. float: left;
  38. text-align: left;
  39. padding-top: 20px;
  40. }
  41. #directions-panel {
  42. margin-top: 20px;
  43. background-color: #FFEE77;
  44. padding: 10px;
  45. }
  46. </style>
  47. </head>
  48. <body>
  49. <div id="map"></div>
  50. <div id="right-panel">
  51. <div>
  52. <b>Start:</b>
  53. <select id="start">
  54. <option value="Halifax, NS">Halifax, NS</option>
  55. <option value="Boston, MA">Boston, MA</option>
  56. <option value="New York, NY">New York, NY</option>
  57. <option value="Miami, FL">Miami, FL</option>
  58. </select>
  59. <br>
  60. <b>Waypoints:</b> <br>
  61. <i>(Ctrl-Click for multiple selection)</i> <br>
  62. <select multiple id="waypoints">
  63. <option value="montreal, quebec">Montreal, QBC</option>
  64. <option value="toronto, ont">Toronto, ONT</option>
  65. <option value="chicago, il">Chicago</option>
  66. <option value="winnipeg, mb">Winnipeg</option>
  67. <option value="fargo, nd">Fargo</option>
  68. <option value="calgary, ab">Calgary</option>
  69. <option value="spokane, wa">Spokane</option>
  70. </select>
  71. <br>
  72. <b>End:</b>
  73. <select id="end">
  74. <option value="Vancouver, BC">Vancouver, BC</option>
  75. <option value="Seattle, WA">Seattle, WA</option>
  76. <option value="San Francisco, CA">San Francisco, CA</option>
  77. <option value="Los Angeles, CA">Los Angeles, CA</option>
  78. </select>
  79. <br>
  80. <input type="submit" id="submit">
  81. </div>
  82. <div id="directions-panel"></div>
  83. </div>
  84. <script>
  85. function initMap() {
  86. var directionsService = new google.maps.DirectionsService;
  87. var directionsDisplay = new google.maps.DirectionsRenderer;
  88. var map = new google.maps.Map(document.getElementById('map'), {
  89. zoom: 6,
  90. center: {lat: 41.85, lng: -87.65}
  91. });
  92. directionsDisplay.setMap(map);
  93. document.getElementById('submit').addEventListener('click', function() {
  94. calculateAndDisplayRoute(directionsService, directionsDisplay);
  95. });
  96. }
  97. function calculateAndDisplayRoute(directionsService, directionsDisplay) {
  98. var waypts = [];
  99. console.log(waypts)
  100. var checkboxArray = document.getElementById('waypoints');
  101. for (var i = 0; i < checkboxArray.length; i++) {
  102. if (checkboxArray.options[i].selected) {
  103. waypts.push({
  104. location: checkboxArray[i].value,
  105. stopover: true
  106. });
  107. }
  108. }
  109. directionsService.route({
  110. origin: document.getElementById('start').value,
  111. destination: document.getElementById('end').value,
  112. waypoints: waypts,
  113. optimizeWaypoints: true,
  114. travelMode: google.maps.TravelMode.DRIVING
  115. }, function(response, status) {
  116. if (status === google.maps.DirectionsStatus.OK) {
  117. directionsDisplay.setDirections(response);
  118. var route = response.routes[0];
  119. var summaryPanel = document.getElementById('directions-panel');
  120. summaryPanel.innerHTML = '';
  121. // For each route, display summary information.
  122. for (var i = 0; i < route.legs.length; i++) {
  123. var routeSegment = i + 1;
  124. summaryPanel.innerHTML += '<b>Route Segment: ' + routeSegment +
  125. '</b><br>';
  126. summaryPanel.innerHTML += route.legs[i].start_address + ' to ';
  127. summaryPanel.innerHTML += route.legs[i].end_address + '<br>';
  128. summaryPanel.innerHTML += route.legs[i].distance.text + '<br><br>';
  129. }
  130. } else {
  131. window.alert('Directions request failed due to ' + status);
  132. }
  133. });
  134. }
  135. </script>
  136. <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCRJmzsM7kO11JVPiPukyS3lzxyWQj4nVU&signed_in=true&callback=initMap"
  137. async defer></script>
  138. </body>
  139. </html>

comments powered by Disqus