afstand-berekenen-dmv-postcodes
Gesponsorde koppelingen
PHP script bestanden
Code (php)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
function zipcodeCalc( $from, $to, $key)
{
$data = array (
'key=' . $key,
'output=json',
'gl=nl',
'q=' . urlencode('from: '.$from.' to: '.$to)
);
$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);
}
$key = 'Google MAPS api sleutel';
$from = 'Postcode, Woonplaats, Land';
$to = 'Postcode, Woonplaats, Land';
$fetch = json_decode( zipcodeCalc( $from, $to, $key) );
echo 'Afstand: '.round($fetch->Directions->Distance->meters/1000,2).' km<br />';
echo 'Tijdsduur: ~'.round($fetch->Directions->Duration->seconds/60).' minuten<br />';
//wow ik kan php afsluiten :o
?>
function zipcodeCalc( $from, $to, $key)
{
$data = array (
'key=' . $key,
'output=json',
'gl=nl',
'q=' . urlencode('from: '.$from.' to: '.$to)
);
$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);
}
$key = 'Google MAPS api sleutel';
$from = 'Postcode, Woonplaats, Land';
$to = 'Postcode, Woonplaats, Land';
$fetch = json_decode( zipcodeCalc( $from, $to, $key) );
echo 'Afstand: '.round($fetch->Directions->Distance->meters/1000,2).' km<br />';
echo 'Tijdsduur: ~'.round($fetch->Directions->Duration->seconds/60).' minuten<br />';
//wow ik kan php afsluiten :o
?>