-
Notifications
You must be signed in to change notification settings - Fork 1
/
getDirections.php
41 lines (36 loc) · 950 Bytes
/
getDirections.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
<?php
require_once("common.inc.php");
$context = stream_context_create( array(
'http'=>array(
'timeout' => 4.0
)
));
for ($i = 0; $i < count($stadia); $i++) {
$stadiumI = $stadia[$i];
for ($j = 0; $j < count($stadia); $j++) {
if ($j == $i) {
continue;
}
$stadiumJ = $stadia[$j];
$filenameOut=$directionsDir."/".$stadiumI[$idxTeamName]." - ".$stadiumJ[$idxTeamName].".json";
$origin=$stadiumI[$idxLat].",".$stadiumI[$idxLon];
$destination=$stadiumJ[$idxLat].",".$stadiumJ[$idxLon];
$url="http://maps.googleapis.com/maps/api/directions/json?origin=".$origin."&destination=".$destination."&sensor=false";
echo "fetching ".$filenameOut." …";
$fh = @fopen($url, 'r', false, $context);
if ($fh) {
file_put_contents($filenameOut, $fh);
@fclose($fh);
echo " done\n";
} else {
// retry
$j--;
echo " retrying…\n";
@fclose($fh);
continue;
}
// to stop requests blocking
sleep(2);
}
}
?>