$from = "Санкт-Петергубг Ленина 5";
$to = "Выборг Ленина 20";
$from = urlencode($from);
$to = urlencode($to);
$data = file_get_contents("http://maps.googleapis.com/maps/api/distancematrix/json?origins=$from&destinations=$to&language=ru-RU&sensor=false");
$data = json_decode($data);
echo "Откуда: ".$data->destination_addresses[0] . "<br/>" .
"Куда: ". $data->origin_addresses[0] . "<br/>" .
"Время: ". $data->rows[0]->elements[0]->distance->text . "<br/>" .
"Путь: ".$data->rows[0]->elements[0]->duration->text;