Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.45 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>CMPT 350 Assignment 1</title>
  7.         <style>
  8.             <!-- Map Style Settings -->
  9.             html, body, #map-canvas {
  10.                 height: 100%;
  11.                 width: 90%;
  12.                 margin: 0px;
  13.                 padding: 0px
  14.             }
  15.             <!-- Notification Panel Settings -->
  16.             #panel {
  17.                 position: absolute;
  18.                 top: 5px;
  19.                 left: 50%;
  20.                 margin-left: -180px;
  21.                 z-index: 5;
  22.                 background-color: #fff;
  23.                 padding: 5px;
  24.                 border: 1px solid #999;
  25.             }
  26.         </style>
  27.         <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
  28.         <script>
  29.             var directionsDisplay;
  30.             var directionsService = new google.maps.DirectionsService();
  31.             var haight = new google.maps.LatLng(37.7699298, -122.4469157);
  32.             var oceanBeach = new google.maps.LatLng(37.7683909618184, -122.51089453697205);
  33.            
  34.             function initialize() {        
  35.                 // variables for directions display and for default location
  36.                 directionsDisplay = new google.maps.DirectionsRenderer();
  37.                 var myLatlng = new google.maps.LatLng(52.13122,-106.65175);
  38.                
  39.                 // Setting for the map
  40.                 var mapOptions = {
  41.                     zoom: 12,
  42.                     center: myLatlng
  43.                 }
  44.                 // Defining the map and setting the directions display to said map
  45.                 var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
  46.                 directionsDisplay.setMap(map);
  47.  
  48.                 // Add initial marker
  49.                 var marker = new google.maps.Marker({
  50.                     position: myLatlng,
  51.                     map: map,
  52.                     title: 'Current Position'
  53.                 });
  54.                 /*
  55.                 // testing for geolocation compatibility
  56.                 if(navigator.geolocation) {
  57.                     browserSupportFlag = true;
  58.                     navigator.geolocation.getCurrentPosition(function(position) {
  59.                     initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
  60.                     map.setCenter(initialLocation);
  61.                     }, function() {
  62.                         handleNoGeolocation(browserSupportFlag);
  63.                     });
  64.                 }
  65.                 // If not compatible
  66.                 else {
  67.                     browserSupportFlag = false;
  68.                     handleNoGeolocation(browserSupportFlag);
  69.                 }
  70.                
  71.                 // If geolocation fails
  72.                 function handleNoGeolocation(errorFlag) {
  73.                     if (errorFlag == true) {
  74.                         alert("Geolocation service failed.");
  75.                         initialLocation = newyork;
  76.                     } else {
  77.                         alert("Your browser doesn't support geolocation. We've placed you in Siberia.");
  78.                         initialLocation = siberia;
  79.                     }
  80.                     map.setCenter(initialLocation);
  81.                 }
  82.                 */
  83.             }
  84.             //Calculate the route
  85.             function calcRoute() {
  86.                 var selectedMode = document.getElementById('mode').value;
  87.                 var request = {
  88.                     origin: haight,
  89.                     destination: oceanBeach,
  90.                     travelMode: google.maps.TravelMode[selectedMode]
  91.                 };
  92.                 directionsService.route(request, function(response, status) {
  93.                     if (status == google.maps.DirectionsStatus.OK) {
  94.                         directionsDisplay.setDirections(response);
  95.                     }
  96.                 });
  97.             }
  98.             //Initialize on window load
  99.             google.maps.event.addDomListener(window, 'load', initialize);
  100.         </script>
  101.   </head>
  102.  
  103.   <body>
  104.         <!-- travel mode panel -->
  105.         <div id="panel">
  106.             <b>Mode of Travel: </b>
  107.             <select id="mode" onchange="calcRoute();">
  108.                 <option value="DRIVING">Driving</option>
  109.                 <option value="WALKING">Walking</option>
  110.                 <option value="BICYCLING">Bicycling</option>
  111.                 <option value="TRANSIT">Transit</option>
  112.             </select>
  113.         </div>
  114.         <!-- map panel -->
  115.         <div id="map-canvas"></div>
  116.   </body>
  117. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement