Mursaleen Hassan

Mursaleen Hassan

  • NA
  • 22
  • 4.5k

Google Map multiple routes using Asp.Net

Apr 19 2018 4:36 PM
Hi,
 
Please help me, I am tired to create multiple routes in google map through javascript using asp.net. In deply i am saying a visual studio SQL Server connectivity to google map and automatically all routes are created.
 
thanks for advance 
 
Example:
 
 
This is Index.cshtml
  1. @{    
  2.     ViewBag.Title = "Home Page";    
  3. }    
  4.     
  5. <style>    
  6.     #map {    
  7.         height: 500px;    
  8.     }    
  9. </style>    
  10. <br /><br/>    
  11. <div id="map"></div>    
  12.     
  13. <script>    
  14.     var map;    
  15.     function initMap() {    
  16.         var directionsService = new google.maps.DirectionsService;    
  17.         var directionsDisplay = new google.maps.DirectionsRenderer;    
  18.         map = new google.maps.Map(document.getElementById('map'), {    
  19.             center: { lat: 25.370442, lng: 68.353753 },    
  20.             zoom: 5    
  21.         });    
  22.     
  23.     
  24.         $.get("@Url.Action("GetAllLocation1","Home")"function (data, status) {    
  25.                 
  26.             for (var i = 0; i < data.length; i++) {    
  27.                 directionsDisplay.setMap(map);       
  28.     
  29.                 var onChangeHandler = function () {    
  30.                     calculateAndDisplayRoute(directionsService, directionsDisplay);    
  31.                 };    
  32.                 document.getElementById(data[i].p1).addEventListener('change', onChangeHandler);    
  33.                 document.getElementById(data[i].p2).addEventListener('change', onChangeHandler);    
  34.     
  35.     
  36.                 function calculateAndDisplayRoute(directionsService, directionsDisplay) {    
  37.                     directionsService.route({    
  38.                         origin: document.getElementById(data[i].p1).value,    
  39.                         destination: document.getElementById(data[i].p2).value,    
  40.                         travelMode: 'DRIVING'    
  41.                     }, function (response, status) {    
  42.                         if (status === 'OK') {    
  43.                             directionsDisplay[i].setDirections(response);    
  44.                         } else {    
  45.                             window.alert('Directions request failed due to ' + status);    
  46.                         }    
  47.                     });    
  48.                 }    
  49.             }    
  50.         });    
  51.     }    
  52. </script>    
  53.     
  54. <script src="https://maps.googleapis.com/maps/api/js?key=xxxxXXXXxxxxx&callback=initMap" async defer></script>  
This is sql server database
 
 

Answers (2)