Hi This one will Helpfull for you ,
Small Example of Direction Service, i'm using the center point of FROM address , and TO address where ever you clicking it will takes the TO address . the map draw the driving root .
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Google Maps JavaScript API v3 Example: Directions Travel Modes</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<input type="text" id="from_Latlng" value="12.9301397, 77.58773180000003" />
<input type="text" id="to_Latlng" value="" />
<script>
$(function(){ initialize(); });
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
var From = new google.maps.LatLng(12.9301397, 77.58773180000003);
var to_latLng=$("#to_Latlng").val();
if(to_latLng!='')
{
var to_LatLngSplit=to_latLng.split(",");
var to_lat=to_LatLngSplit[0];
var to_lng=to_LatLngSplit[1];
var to = new google.maps.LatLng(to_lat,to_lng);
}
else
{
var to = new google.maps.LatLng(12.9997841, 77.68394269999999);
}
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: From
}
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
// If there are any parameters at eh end of the URL, they will be in location.search
var lat,lng,zoom,type;
//looking something like "?marker=3"
directionsDisplay.setMap(map);
calcRoute(From,to);
google.maps.event.addListener(map, 'click', function (e) {
//alert("Latitude: " + e.latLng.lat() + "\r\nLongitude: " + e.latLng.lng());// i got TO address Latitude , Longitude value
$('#to_Latlng').val(e.latLng.lat()+","+e.latLng.lng());
initialize();
});
}
function calcRoute(From,to) {
var selectedMode = "DRIVING";
var request = {
origin: From,
destination: to,
travelMode: google.maps.TravelMode[selectedMode]
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
alert("Directions Request Failed, "+status);
}
});
}
</script>
</head>
<body onload="initialize()">
<div>
<b>Mode of Travel: </b>
</div>
<div id="map_canvas" style="height: 450px;"></div>
</body>
</html>
Demo