Retrieve KML from Routes drawn on map using Google Map API v3.

71 views
Skip to first unread message

pradeep...@gmail.com

unread,
Jan 28, 2015, 5:28:52 AM1/28/15
to kml-support-g...@googlegroups.com
I am able to get the route directions between two places on the map. There are multiple routes (PFA of the result I am getting). I want the KML file to be retrieved from those resulting routes. Can anyone help me retrieving the KML format of the routes.

I used the following code for displaying the routes.

function calcRoute() 
{
  var start = document.getElementById('start').value;
  var end = document.getElementById('end').value;
  var directionsRequest = {
      origin:start,
      destination:end,
      provideRouteAlternatives: true,
      travelMode: google.maps.DirectionsTravelMode.DRIVING,
      unitSystem: google.maps.UnitSystem.METRIC
    };
  directionsService.route(directionsRequest,
      function (response, status) {
          if (status == google.maps.DirectionsStatus.OK) {
   if(directionsDisplay != null) {
   directionsDisplay.setMap(null);
   directionsDisplay = null;
   map = null;
   }
   directionsDisplay = new google.maps.DirectionsRenderer();
            map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
   directionsDisplay.setMap(map);
            for (var i = 0, len = response.routes.length; i < len; i++) {
                new google.maps.DirectionsRenderer({
                    map: map,
                    directions: response,
                    routeIndex: i,
   draggable: true
                });
            }
alert(ctaLayer.getUrl());
          } else {
             $("#error").append("Unable to retrieve your route<br />");
          }
      }
  );
}
Direction Service1.png
Reply all
Reply to author
Forward
0 new messages