scripts/routeCreation.js
/**
 * Draw a Line on Google Earth using the data retrieved from the Google Maps DirectionsService
 * @param {DirectionsResult} directionsResult The result returned from the Google Maps DirectionsService,
 *							 containing all mapping information needed to perform further processing and
 *							 calculations for the route that has been requested to be drawn
 * @param {ModelSimulator} simulator The simulator to create a route for
 */
Draw a Line on Google Earth using the data retrieved from the Google Maps DirectionsService
@param {DirectionsResult} directionsResult The result returned from the Google Maps DirectionsService,
containing all mapping information needed to perform further processing and
calculations for the route that has been requested to be drawn
@param {ModelSimulator} simulator The simulator to create a route for
Draw a Line on Google Earth using the data retrieved from the Google Maps DirectionsService @param { DirectionsResult } directionsResult The result returned from the Google Maps DirectionsService containing all mapping information needed to perform further processing and calculations for the route that has been requested to be drawn @param { ModelSimulator } simulator The simulator to create a route for
function drawRouteLine(directionsResult, simulator) {
	var directionsRoute = directionsResult.routes[0]; 
	var kmlLineString = "<LineString><coordinates>\n";  
	for(var i = 0; i < directionsRoute.legs.length; i++) {
	    simulator.requiredTravelTime += directionsRoute.legs[i].duration.value; 
		for(var j = 0; j < directionsRoute.legs[i].steps.length; j++) {
			for(var k = 0; k < directionsRoute.legs[i].steps[j].path.length; k++) {	
				var currentLongitude = directionsRoute.legs[i].steps[j].path[k].lng();
				var currentLatitude = directionsRoute.legs[i].steps[j].path[k].lat();
				kmlLineString += appendToKmlLineString(currentLongitude, currentLatitude);
				determineAdditionalPathDetails(directionsRoute.legs[i].steps[j], j, k, simulator);
			}
		}
	}
	kmlLineString += "</coordinates></LineString>"; 
	appendKmlLineStringToEarth(kmlLineString, simulator);
}
function drawRouteLine ( directionsResult , simulator ) { var directionsRoute = directionsResult . routes [ 0 ] ; var kmlLineString = "<LineString><coordinates>\n" ; for ( var i = 0 ; i < directionsRoute . legs . length ; i ++ ) { simulator . requiredTravelTime += directionsRoute . legs [ i ] . duration . value ; for ( var j = 0 ; j < directionsRoute . legs [ i ] . steps . length ; j ++ ) { for ( var k = 0 ; k < directionsRoute . legs [ i ] . steps [ j ] . path . length ; k ++ ) { var currentLongitude = directionsRoute . legs [ i ] . steps [ j ] . path [ k ] . lng ( ) ; var currentLatitude = directionsRoute . legs [ i ] . steps [ j ] . path [ k ] . lat ( ) ; kmlLineString += appendToKmlLineString ( currentLongitude , currentLatitude ) ; determineAdditionalPathDetails ( directionsRoute . legs [ i ] . steps [ j ] , j , k , simulator ) ; } } } kmlLineString += "</coordinates></LineString>" ; appendKmlLineStringToEarth ( kmlLineString , simulator ) ; }
Draw a Line on Google Earth using the data retrieved from the Google Maps DirectionsService
 @param {DirectionsResult} directionsResult The result returned from the Google Maps DirectionsService,
                                                       containing all mapping information needed to perform further processing and
                                                       calculations for the route that has been requested to be drawn
 @param {ModelSimulator} simulator The simulator to create a route for
Draw a Line on Google Earth using the data retrieved from the Google Maps DirectionsService @param { DirectionsResult } directionsResult The result returned from the Google Maps DirectionsService containing all mapping information needed to perform further processing and calculations for the route that has been requested to be drawn @param { ModelSimulator } simulator The simulator to create a route for
//There is only one DirectionsRoute unless the provideRouteAlternatives attribute of a DirectionsRequest is true - in this application this is never the case //The opening tags for the KML Line String //For every DirectionsLeg (there will be 1 DirectionsLeg unless waypoints have been specified) //Count the total duration of the route //And every DirectionsStep in every DirectionsLeg //And every LatLng in every DirectionsStep in every DirectionsLeg //Get the current latitude and longitude //And add them to the kmlLineString using the appropriate syntax //The closing tags for the KML Line String