Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  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. /* Always set the map height explicitly to define the size of the div
  9. * element that contains the map. */
  10. #map {
  11. height: 100%;
  12. }
  13. /* Optional: Makes the sample page fill the window. */
  14. html, body {
  15. height: 100%;
  16. margin: 0;
  17. padding: 0;
  18. }
  19. #floating-panel {
  20. position: absolute;
  21. top: 10px;
  22. left: 25%;
  23. z-index: 5;
  24. background-color: #fff;
  25. padding: 5px;
  26. border: 1px solid #999;
  27. text-align: center;
  28. font-family: 'Roboto','sans-serif';
  29. line-height: 30px;
  30. padding-left: 10px;
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <div id="floating-panel">
  36. <b>End: </b>
  37. <select id="end">
  38. <option value="52.235221, 21.037156">Warszawa</option>
  39. <option value="54.518853, 18.530769">Gdynia</option>
  40. <option value="54.441550, 18.560256">Sopot</option>
  41. </select>
  42. </div>
  43. <div id="map"></div>
  44. <script>
  45. function initMap() {
  46. var directionsService = new google.maps.DirectionsService;
  47. var directionsDisplay = new google.maps.DirectionsRenderer;
  48. var map = new google.maps.Map(document.getElementById('map'), {
  49. zoom: 14,
  50. center: {lat: 54.371772, lng: 18.612774}
  51. });
  52. directionsDisplay.setMap(map);
  53.  
  54. var onChangeHandler = function() {
  55. calculateAndDisplayRoute(directionsService, directionsDisplay);
  56. };
  57. document.getElementById('end').addEventListener('change', onChangeHandler);
  58. }
  59.  
  60. function calculateAndDisplayRoute(directionsService, directionsDisplay) {
  61. var WETI = new google.maps.LatLng(54.371772, 18.612774);
  62. var TARGET = new google.maps.LatLng(document.getElementById('end').value.addEventListener('change', onChangeHandler));
  63. directionsService.route({
  64. origin: WETI,
  65. destination: TARGET,
  66. travelMode: 'DRIVING'
  67. }, function(response, status) {
  68. if (status === 'OK') {
  69. directionsDisplay.setDirections(response);
  70. } else {
  71. window.alert('Directions request failed due to ' + status);
  72. }
  73. });
  74. }
  75. </script>
  76. <script async defer
  77. src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAZ0J3NDxWyTyT4bZocbESU-DQXekbZdD4&callback=initMap">
  78. </script>
  79. </body>
  80. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement