Guest User

Untitled

a guest
Nov 23rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. $('document').ready(function(){
  2. $('#geobutton').click(determineLocation);
  3. $('#showwaybutton').click(letsGo);
  4. });
  5.  
  6. var address1;
  7. var address2;
  8. var map;
  9.  
  10. function initialize() {
  11.  
  12. var myOptions = {
  13. zoom: 12,
  14. center: new google.maps.LatLng(49.844808, 8.858109),
  15. mapTypeId: google.maps.MapTypeId.ROADMAP,
  16. mapTypeControl: true,
  17. scaleControl: false,
  18. navigationControl: true,
  19. navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
  20. streetViewControl: false
  21. };
  22.  
  23. map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
  24.  
  25. }
  26.  
  27. google.maps.event.addDomListener(window, "load", initialize);
  28.  
  29.  
  30.  
  31. function letsGo() {
  32. address1 = document.getElementById("address1").value;
  33. address2 = "Fasanenhof Habitzheim 9, 64853 Otzberg";
  34. showMap();
  35. }
  36.  
  37.  
  38.  
  39. function showMap() {
  40. var mapOptions = {
  41. zoom: 12,
  42. center: new google.maps.LatLng(49.844808, 8.858109),
  43. mapTypeId: google.maps.MapTypeId.ROADMAP,
  44. mapTypeControl: true,
  45. scaleControl: false,
  46. navigationControl: true,
  47. navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
  48. streetViewControl: false
  49. };
  50.  
  51. map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
  52.  
  53. // show route between the points
  54. directionsService = new google.maps.DirectionsService();
  55. directionsDisplay = new google.maps.DirectionsRenderer();
  56. directionsDisplay.setMap(map);
  57. var request = {
  58. origin:address1,
  59. destination:address2,
  60. travelMode: google.maps.DirectionsTravelMode.DRIVING
  61. };
  62. directionsDisplay.setPanel(document.getElementById("map-directions"));
  63. directionsService.route(request, function(result, status) {
  64. if (status != google.maps.DirectionsStatus.OK) {
  65. alert('Directions failed: ' + status);
  66. return;
  67. } else {
  68. directionsDisplay.setDirections(result);
  69. }
  70. });
  71. }
  72.  
  73.  
  74.  
  75. function determineLocation() {
  76. var directionsService = new google.maps.DirectionsService(),
  77. directionsDisplay = new google.maps.DirectionsRenderer(),
  78.  
  79. createMapy = function (start) {
  80. var myOptions = {
  81. zoom: 12,
  82. center: new google.maps.LatLng(49.844808, 8.858109),
  83. mapTypeId: google.maps.MapTypeId.ROADMAP,
  84. mapTypeControl: true,
  85. scaleControl: false,
  86. navigationControl: true,
  87. navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
  88. streetViewControl: false
  89. };
  90.  
  91. map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
  92.  
  93. };
  94.  
  95. createMap = function (start) {
  96. var travel = {
  97. origin : (start.coords)? new google.maps.LatLng(start.lat, start.lng) : start.address,
  98. destination : "Fasanenhof Habitzheim 9, 64853 Otzberg",
  99. travelMode : google.maps.DirectionsTravelMode.DRIVING
  100. },
  101. mapOptions = {
  102. zoom: 12,
  103. center: new google.maps.LatLng(49.844808, 8.858109),
  104. mapTypeId: google.maps.MapTypeId.ROADMAP,
  105. mapTypeControl: true,
  106. scaleControl: false,
  107. navigationControl: true,
  108. navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
  109. streetViewControl: false
  110. };
  111.  
  112. map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
  113. directionsDisplay.setMap(map);
  114. directionsDisplay.setPanel(document.getElementById("map-directions"));
  115. directionsService.route(travel, function(result, status) {
  116. if (status != google.maps.DirectionsStatus.OK) {
  117. alert('Directions failed: ' + status);
  118. return;
  119. } else {
  120. directionsDisplay.setDirections(result);
  121. }
  122. });
  123. };
  124.  
  125. // Check for geolocation support
  126. if (navigator.geolocation) {
  127. navigator.geolocation.getCurrentPosition(function (position) {
  128. // Success!
  129. createMap({
  130. coords : true,
  131. lat : position.coords.latitude,
  132. lng : position.coords.longitude
  133. });
  134. }, function () {
  135. // Gelocation fallback:
  136. createMapy();
  137. });
  138. } else if (google.gears) {
  139. // Try Google Gears Geolocation
  140.  
  141. } else {
  142. // No geolocation fallback:
  143. createMapy();
  144. }
  145. }
Add Comment
Please, Sign In to add comment