1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
<?php
$adresse1="Paris";
$adresse2="Bordeaux";
/*$adresse1=str_replace(" ","+", $adresse1);
$adresse2=str_replace(" ","+", $adresse2);
*/
function getDistance($adresse1,$adresse2){
$url="http://maps.google.com/maps/api/directions/xml?language=fr&origin=".$adresse1."&destination=".$adresse2."&sensor=false";
$xml=file_get_contents($url);
$root = simplexml_load_string($xml);
$distance=$root->route->leg->distance->value;
if ($root->status == "OK")
{
return $distance;
}
else
{
return "0";
}
}
echo getDistance($adresse1,$adresse2)." m";
?> |