";
// адрес или координаты пунктов назначения
$params['destinations'] = "Россия, Санкт-Петербург, станция метро ".$mtr;
echo $params['destinations']."
";
$params = http_build_query($params);
$url = "http://maps.googleapis.com/maps/api/distancematrix/json?" . $params;
echo $url;
$json = file_get_contents($url);
echo $json."
";
$json = json_decode($json, true);
$meters = 0;
$peshkom = 0;
$transport = 0;
if ($json['status'] == "OK" && $json['rows'] && $json['rows'][0] && $json['rows'][0]['elements'] && $json['rows'][0]['elements'][0] && $json['rows'][0]['elements'][0]['status'] == "OK") {
$meters = $json['rows'][0]['elements'][0]['distance']['value'];
}
if ($meters > 0) {
if ($meters <= 100) {
$peshkom = 1;
} else {
if ($meters <= 2000) {
$peshkom = round($meters / 100);
} else {
$transport = round($meters / 1000);
}
}
}
echo "Метры: ".$meters." Пешком: ".$peshkom." Транспортом: ".$transport;
}
}