The DirectionsService object calculates directions (using a variety of methods of transportation) and returns a route using the Google Maps API Directions Service which receives direction requests and returns computed results. Directions results can be displayed on the map by using the DirectionsRenderer.
Official documentation:
https://developers.google.com/maps/documentation/javascript/directions
Stackoverflow question "Google Maps API V3 : How show the direction from a point A to point B" (http://stackoverflow.com/questions/5959788/google-maps-api-v3-how-show-the-direction-from-a-point-a-to-point-b-blue-line)