As I know it this isn't official and google doesn't support it but it works:
$url = str_replace(' ', '%20', "http://maps.google.com/maps/nav?client=yourclient&output=json&q=from: ".$lat1.",".$lon1." to: ".$lat2.",".$lon2);
$result = file_get_contents($url);
$data = json_decode(utf8_encode($result), true);
And you'll have directions in $data array.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…