You can use the GDirections.getDistance() and GDirections.getDuration() methods, as shown in the following example:
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <title>Google Maps GDirections Demo</title> <script src="http://maps.google.com/maps?file=api&v=2&sensor=false" type="text/javascript"></script> </head> <body onunload="GUnload()" style="font-family: Arial; font-size: 12px;"> <div id="map" style="width: 400px; height: 300px"></div> <div id="duration">Duration: </div> <div id="distance">Distance: </div> <script type="text/javascript"> var map = new GMap2(document.getElementById("map")); var directions = new GDirections(map); directions.load("from: Chennai, India to: Mumbai, India"); GEvent.addListener(directions, "load", function() { </script> </body> </html>

source share