Advertisement
Guest User

Untitled

a guest
Aug 7th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.47 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="utf-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.  
  7.     <!-- Google Maps script -->
  8.     <script type="text/javascript"
  9.         src="http://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxxxxxxxxxxxx&sensor=false">
  10.     </script>
  11.     <script type="text/javascript">
  12.       var directionDisplay;
  13.       var directionsService = new google.maps.DirectionsService();
  14.       var map;
  15.  
  16.       function initialize() {
  17.         directionsDisplay = new google.maps.DirectionsRenderer();
  18.         var philadelphia = new google.maps.LatLng(39.9522, -75.1642);
  19.         var mapOptions = {
  20.           center: philadelphia,
  21.           zoom: 7,
  22.           mapTypeId: google.maps.MapTypeId.ROADMAP,
  23.           disableDefaultUI: true,
  24.         };
  25.         map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
  26.         directionsDisplay.setMap(map);
  27.       }
  28.  
  29.       function calcRoute() {
  30.         var start = document.getElementById('start').value;    
  31.         var end = document.getElementById('end').value;
  32.  
  33.         var request = {
  34.           origin:start,
  35.           destination:end,
  36.           travelMode: google.maps.DirectionsTravelMode.DRIVING,
  37.         };
  38.  
  39.         directionsService.route(request, function(response, status) {
  40.           if (status == google.maps.DirectionsStatus.OK) {
  41.             directionsDisplay.setDirections(response);
  42.           }
  43.         });
  44.       }
  45.     </script>
  46.   </head>
  47.  
  48.   <body onload="initialize()">
  49.  
  50.     <div class="container" style="height: 100%">
  51.       <div>
  52.       <form class="form-horizontal" onsubmit="return calcRoute()">
  53.         <fieldset>
  54.           <div class="control-group">
  55.         <label class="control-label" for="start">From</label>  
  56.         <div class="controls">
  57.           <input type="text" class="input-xlarge" id="start" placeholder="Origin">
  58.         </div>
  59.           </div> <!-- /"start" control-group -->
  60.           <div class="control-group">
  61.         <label class="control-label" for="finish">To</label>   
  62.         <div class="controls">
  63.           <input type="text" class="input-xlarge" id="end" placeholder="Destination">
  64.         </div>
  65.           </div> <!-- /"finish" control-group -->
  66.           <div class="controls">
  67.         <input class="btn btn-primary offset2" type="submit" value="Let's go!">
  68.           </div> <!-- Submit button -->
  69.         </fieldset>
  70.       </form> <!-- /trip info -->
  71.     </div>
  72.  
  73.     <div>
  74.       <div id="map_canvas" ></div>
  75.     </div>
  76.  
  77.     </div> <!-- /container -->
  78.  
  79.   </body>
  80. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement