index_map.tpl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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>Directions service</title>
  7. <style>
  8. html, body {
  9. height: 100%;
  10. margin: 0;
  11. padding: 0;
  12. }
  13. #map {
  14. height: 100%;
  15. }
  16. #floating-panel {
  17. position: absolute;
  18. top: 10px;
  19. left: 25%;
  20. z-index: 5;
  21. background-color: #fff;
  22. padding: 5px;
  23. border: 1px solid #999;
  24. text-align: center;
  25. font-family: 'Roboto','sans-serif';
  26. line-height: 30px;
  27. padding-left: 10px;
  28. }
  29. </style>
  30. </head>
  31. <body>
  32. <div id="floating-panel">
  33. <b>Start: </b>
  34. <select id="start" onchange="calcRoute();">
  35. <option value="华盛达广场, 杭州">华盛达广场, 杭州</option>
  36. <option value="st louis, mo">St Louis</option>
  37. <option value="joplin, mo">Joplin, MO</option>
  38. <option value="oklahoma city, ok">Oklahoma City</option>
  39. <option value="amarillo, tx">Amarillo</option>
  40. <option value="gallup, nm">Gallup, NM</option>
  41. <option value="flagstaff, az">Flagstaff, AZ</option>
  42. <option value="winona, az">Winona</option>
  43. <option value="kingman, az">Kingman</option>
  44. <option value="barstow, ca">Barstow</option>
  45. <option value="san bernardino, ca">San Bernardino</option>
  46. <option value="los angeles, ca">Los Angeles</option>
  47. </select>
  48. <b>End: </b>
  49. <select id="end" onchange="calcRoute();">
  50. <option value="西湖文化广场, 杭州">西湖文化广场, 杭州</option>
  51. <option value="st louis, mo">St Louis</option>
  52. <option value="joplin, mo">Joplin, MO</option>
  53. <option value="oklahoma city, ok">Oklahoma City</option>
  54. <option value="amarillo, tx">Amarillo</option>
  55. <option value="gallup, nm">Gallup, NM</option>
  56. <option value="flagstaff, az">Flagstaff, AZ</option>
  57. <option value="winona, az">Winona</option>
  58. <option value="kingman, az">Kingman</option>
  59. <option value="barstow, ca">Barstow</option>
  60. <option value="san bernardino, ca">San Bernardino</option>
  61. <option value="los angeles, ca">Los Angeles</option>
  62. </select>
  63. </div>
  64. <div id="map"></div>
  65. <script>
  66. function initMap() {
  67. var directionsService = new google.maps.DirectionsService;
  68. var directionsDisplay = new google.maps.DirectionsRenderer;
  69. var map = new google.maps.Map(document.getElementById('map'), {
  70. zoom: 7,
  71. center: {lat: 41.85, lng: -87.65}
  72. });
  73. directionsDisplay.setMap(map);
  74. var onChangeHandler = function() {
  75. calculateAndDisplayRoute(directionsService, directionsDisplay);
  76. };
  77. document.getElementById('start').addEventListener('change', onChangeHandler);
  78. document.getElementById('end').addEventListener('change', onChangeHandler);
  79. }
  80. function calculateAndDisplayRoute(directionsService, directionsDisplay) {
  81. directionsService.route({
  82. origin: document.getElementById('start').value,
  83. destination: document.getElementById('end').value,
  84. travelMode: google.maps.TravelMode.DRIVING,
  85. provideRouteAlternatives:true
  86. }, function(response, status) {
  87. if (status === google.maps.DirectionsStatus.OK) {
  88. directionsDisplay.setDirections(response);
  89. } else {
  90. window.alert('Directions request failed due to ' + status);
  91. }
  92. });
  93. }
  94. </script>
  95. <script src="http://maps.google.cn/maps/api/js?key=AIzaSyD_MW2d9ttF1T8_xFbVkzjiaQwWiPFrvc8&callback=initMap"
  96. async defer></script>
  97. </body>
  98. </html>