Function NavigationTool (){
Var mode = google. maps. DirectionsTravelMode. DRIVING; // google map route guide mode
Var directionsDisplay = new google. maps. DirectionsRenderer (); // map route Display object
Var directionsService = new google. maps. DirectionsService (); // map route service object
Var directionsVisible = false; // whether to display the route
DirectionsDisplay. setMap (null );
DirectionsDisplay. setMap (map );
Var Navigpoints = []; // start and end point
Google. maps. event. addListener (map, "click", function (evt ){
If (Navigpoints. length = 0 ){
If (confirm ("do you want to set the current vertex as the starting point? ")){
Navigpoints. push (evt. latLng );
}
} Else {
If (Navigpoints. length> = 2) {points = []; google. maps. event. clearListeners (map, "click"); return ;}
If (confirm ("do you want to set the current vertex as the end point? ")){
Navigpoints. push (evt. latLng );
Var request = {
Origin: Navigpoints [0], // start point
Destination: Navigpoints [1], // endpoint
TravelMode: mode,
OptimizeWaypoints: true,
AvoidHighways: false,
AvoidTolls: false
};
DirectionsService. route (
Request,
Function (response, status ){
If (status = google. maps. DirectionsStatus. OK ){
DirectionsDisplay. setDirections ctions (response );
// Regularly clear the line
SetTimeout (function () {diresdsdisplay. setMap (null)}, 8000 );
}
}
);
}
}
});
DirectionsVisible = true;
}