Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

show route between markers google maps javascript

function mapLocation() {
  var directionsDisplay;
  var directionsService = new google.maps.DirectionsService();
  var map;

  function initialize() {
    directionsDisplay = new google.maps.DirectionsRenderer();
    var chicago = new google.maps.LatLng(37.334818, -121.884886);
    var mapOptions = {
      zoom: 7,
      center: chicago
    };
    map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
    directionsDisplay.setMap(map);
    google.maps.event.addDomListener(document.getElementById('routebtn'), 'click', calcRoute);
  }

  function calcRoute() {
    var start = new google.maps.LatLng(37.334818, -121.884886);
    //var end = new google.maps.LatLng(38.334818, -181.884886);
    var end = new google.maps.LatLng(37.441883, -122.143019);
    var request = {
      origin: start,
      destination: end,
      travelMode: google.maps.TravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
        directionsDisplay.setMap(map);
      } else {
        alert("Directions Request from " + start.toUrlValue(6) + " to " + end.toUrlValue(6) + " failed: " + status);
      }
    });
  }

  google.maps.event.addDomListener(window, 'load', initialize);
}
mapLocation();
Comment

PREVIOUS NEXT
Code Example
Javascript :: How to get element margin in React 
Javascript :: currying in javascript mdn 
Javascript :: copy file using java script 
Javascript :: where is the waypoint json file lunar client mac 
Javascript :: material ui table row onclick 
Javascript :: how to send Flutter Color as json || convert String to Color Flutter 
Javascript :: let a local variable 
Javascript :: lavania 
Javascript :: Nested Data Structures 
Javascript :: cookie parser object null prototype 
Javascript :: How to load query params on first render next js 
Javascript :: how is react different from normal js 
Javascript :: set state giving previously update data 
Javascript :: console form elememts as json object 
Javascript :: group by hash in jquery 
Javascript :: javascript browse folder path-limit 
Javascript :: does script defer keep order 
Javascript :: change frame rate javascript 
Javascript :: provider not found react 
Javascript :: remove image Input of element 
Javascript :: axios check if call is already running 
Javascript :: how to rmeove white space in a string with jquery 
Javascript :: animate on scroll angular 
Javascript :: chrome extension sendmessage await until getdata 
Javascript :: how to check a user is using wifi or cellular data in php 
Javascript :: jest simulate toggle switch react native 
Javascript :: node.js how to install a custom version of packgage 
Javascript :: js to jquery ONLINE converter 
Javascript :: angular input .valueChanges.subscribe value 
Javascript :: nuxt js set background color of body 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =