Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function initMap(startLat,startLng,finishLat,finishLng) {
  2.  
  3.             var directionsService = new google.maps.DirectionsService;
  4.             var directionsDisplay = new google.maps.DirectionsRenderer;
  5.  
  6.             var flightPlanCoordinates = [];
  7.             {% for path in trips %}
  8.             flightPlanCoordinates.push({lat: {{ path.startLatitude }},lng: {{ path.startLongitude}}});
  9.             flightPlanCoordinates.push({lat: {{ path.finishLatitude }},lng: {{ path.finishLongitude}}});
  10.             {% endfor %}
  11.  
  12.  
  13.             var map = new google.maps.Map(document.getElementById('map'), {
  14.                 zoom: 20 ,
  15.                 center: flightPlanCoordinates[Math.round(flightPlanCoordinates.length/2)],
  16.                 mapTypeId: 'terrain',
  17.                 scrollwheel: false
  18.             });
  19.  
  20.             var startLatitude = {{ trips|last.startLatitude }};
  21.             var startLongitude = {{ trips|last.startLongitude }};
  22.             var finishLatitude = {{ trips|last.finishLatitude }};
  23.             var finishLongitude = {{ trips|last.finishLongitude }};
  24.             console.log(startLat);
  25.             console.log(startLng);
  26.             console.log(finishLat);
  27.             console.log(finishLng);
  28.             if(typeof startLat !== 'undefined'){
  29.                 startLatitude = startLat;
  30.                 startLongitude = startLng;
  31.                 finishLatitude = finishLat;
  32.                 finishLongitude = finishLng;
  33.             }
  34.  
  35.  
  36.  
  37.             console.log(startLatitude);
  38.             console.log(startLongitude);
  39.             console.log(finishLatitude);
  40.             console.log(finishLongitude);
  41.  
  42.             directionsService.route({
  43.                 origin: {lat: startLatitude,lng: startLongitude},
  44.                 destination: {lat: finishLatitude,lng: finishLongitude},
  45.                 travelMode: 'DRIVING'
  46.             }, function(response, status) {
  47.                 console.log(response);
  48.                 console.log(status);
  49.                 if (status === 'OK') {
  50.                     directionsDisplay.setDirections(response);
  51.                 } else {
  52.                     window.alert('Directions request failed due to ' + status);
  53.                 }
  54.             });
  55.  
  56.             directionsDisplay.setMap(map);
  57.         }
  58.  
  59.     </script>
  60.     <script async defer
  61.             src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB4Kp31r8F7JNRYqfKwZ1PzmCbO0ncCpko&callback=initMap">
  62.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement