Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function initMap(startLat,startLng,finishLat,finishLng) {
- var directionsService = new google.maps.DirectionsService;
- var directionsDisplay = new google.maps.DirectionsRenderer;
- var flightPlanCoordinates = [];
- {% for path in trips %}
- flightPlanCoordinates.push({lat: {{ path.startLatitude }},lng: {{ path.startLongitude}}});
- flightPlanCoordinates.push({lat: {{ path.finishLatitude }},lng: {{ path.finishLongitude}}});
- {% endfor %}
- var map = new google.maps.Map(document.getElementById('map'), {
- zoom: 20 ,
- center: flightPlanCoordinates[Math.round(flightPlanCoordinates.length/2)],
- mapTypeId: 'terrain',
- scrollwheel: false
- });
- var startLatitude = {{ trips|last.startLatitude }};
- var startLongitude = {{ trips|last.startLongitude }};
- var finishLatitude = {{ trips|last.finishLatitude }};
- var finishLongitude = {{ trips|last.finishLongitude }};
- console.log(startLat);
- console.log(startLng);
- console.log(finishLat);
- console.log(finishLng);
- if(typeof startLat !== 'undefined'){
- startLatitude = startLat;
- startLongitude = startLng;
- finishLatitude = finishLat;
- finishLongitude = finishLng;
- }
- console.log(startLatitude);
- console.log(startLongitude);
- console.log(finishLatitude);
- console.log(finishLongitude);
- directionsService.route({
- origin: {lat: startLatitude,lng: startLongitude},
- destination: {lat: finishLatitude,lng: finishLongitude},
- travelMode: 'DRIVING'
- }, function(response, status) {
- console.log(response);
- console.log(status);
- if (status === 'OK') {
- directionsDisplay.setDirections(response);
- } else {
- window.alert('Directions request failed due to ' + status);
- }
- });
- directionsDisplay.setMap(map);
- }
- </script>
- <script async defer
- src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB4Kp31r8F7JNRYqfKwZ1PzmCbO0ncCpko&callback=initMap">
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement