Advertisement
Guest User

Untitled

a guest
Oct 24th, 2013
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. var map;
  2. var startDest = null;
  3. var endDest = null;
  4. var directionsDisplay;
  5. var directionsService = new google.maps.DirectionsService();
  6.  
  7. function initialize() {
  8. directionsDisplay = new google.maps.DirectionsRenderer();
  9. var mapOptions = {
  10. zoom: 7,
  11. mapTypeId: google.maps.MapTypeId.ROADMAP,
  12. center: new google.maps.LatLng(43.757192, -79.337571) // Toronto
  13. };
  14. var map = new google.maps.Map(document.getElementById('map-directions'),
  15. mapOptions);
  16. directionsDisplay.setMap(map);
  17. directionsDisplay.setPanel(document.getElementById('directions-panel'));
  18.  
  19. var control = document.getElementById('control');
  20. control.style.display = 'block';
  21. map.controls[google.maps.ControlPosition.TOP_CENTER].push(control);
  22. }
  23.  
  24. function calcRoute() {
  25. // // First, clear out any existing markerArray from previous calculations.
  26. // for (i = 0; i < markerArray.length; i++) {
  27. // markerArray[i].setMap(null);
  28. // }
  29.  
  30. // // Retrieve the start and end locations from the user and create a DirectionsRequest using TRANSIT directions.
  31. // var start = $("#start-from").val(); //document.getElementById("start").value;
  32. // var end = $("#end-to").val(); //document.getElementById("end").value;
  33. // var request = {
  34. // origin: start,
  35. // destination: end,
  36. // travelMode: google.maps.TravelMode.TRANSIT
  37. // };
  38.  
  39. var start = document.getElementById('start').value;
  40. var end = document.getElementById('end').value;
  41. var request = {
  42. origin: start,
  43. destination: end,
  44. travelMode: google.maps.TravelMode.TRANSIT
  45. };
  46. directionsService.route(request, function(response, status) {
  47. if (status == google.maps.DirectionsStatus.OK) {
  48. directionsDisplay.setDirections(response);
  49. }
  50. });
  51. }
  52.  
  53. google.maps.event.addDomListener(window, 'load', initialize);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement