Ik heb enkele jaren geleden dit script gebruikt.
Nu wens ik het opnieuw te gebruiken maar dit werkt niet meer.
Ik zie ook niet wat er fout is.
Hopelijk kunnen jullie me helpen.
Alvast bedankt.
<?php
function postCodeBerekener($van, $naar) {
$data = array (
'output=json',
'gl=nl',
'q=' . urlencode('from: '.$van.' to: '.$naar)
);
$url = 'http://google.com/maps/nav?' . join('&', $data);
$ch = curl_init( $url);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_MAXREDIRS, 3);
curl_setopt( $ch, CURLOPT_REFERER, 'http://google.com');
$str = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200 ) {
return $str;
} else {
return curl_error( $ch);
}
}
$van = '5643 JR, Eindhoven, Nederland';
$naar = '5692 EN, Son en Breugel, Nederland';
$input = iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode(postCodeBerekener($van, $naar)));
$fetch = json_decode($input);
echo 'Afstand: '.round($fetch->Directions->Distance->meters/1000,2).' km<br />';
echo 'Tijdsduur: ~'.round($fetch->Directions->Duration->seconds/60).' minuten<br />';
?>