Yep, this is definitely possible using the API. You can construct a GDirections object without a map or directions div. You can do a load request from A to B and then call the getDuration method to get the total travel time.
First you need to create a directions object:
// no need to pass map or results div since
// we are only interested in travel time.
var directions = new GDirections ();
Then do your load request to resolve the directions (I have used two latitudes and longitudes as my start and end points, but you can use addresses here as well):
var wp = new Array ();
wp[0] = new GLatLng(32.742149,119.337218);
wp[1] = new GLatLng(32.735347,119.328485);
directions.loadFromWaypoints(wp);
Then you need to listen for the load event so you can call getDuration once the directions have been resolved:
GEvent.addListener(directions, "load", function() {
$('log').innerHTML = directions.getDuration ().seconds + " seconds";
});
You can find the whole example here and the JavaScript here. You can check the Google Maps Documentation for more info about the options you can give the GDirections object (like walking distance etc...). You should also listen to the error event for geocoding failures.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…