Add some friendly name/duplicate subsitution rules
[bus.git] / displaytimepoints.kml.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
header('Content-Type: application/vnd.google-earth.kml+xml');
echo '<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"><Document>';
echo '<Style id="target">
  <IconStyle>
    <Icon>
      <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
    </Icon>
  </IconStyle>
        </Style>';
echo '<Style id="player">
  <IconStyle>
    <Icon>
      <href>http://maps.google.com/mapfiles/kml/pushpin/grn-pushpin.png</href>
    </Icon>
  </IconStyle>
        </Style>';
$conn = pg_connect("dbname=openstreetmap user=postgres password=snmc");
if (!$conn) {
  echo "An error occured.\n";
  exit;
}
/*SELECT * from current_node_tags, (Select id FROM current_node_tags WHERE  "v" LIKE '%bus%') as a
where a.id = current_node_tags.id; */
$result_stops = pg_query($conn, "Select * FROM current_node_tags INNER JOIN current_nodes ON 
current_node_tags.id=current_nodes.id WHERE v LIKE '%bus%' ");
if (!$result_stops) {
  echo "An stops retirieve error occured.\n";
  exit;
}
 
while ($stop = pg_fetch_assoc($result_stops)) {
 echo "\n<Placemark>\n";
 echo "<description>";
$result_stopkeys = pg_query($conn, "SELECT * from current_node_tags where id = {$stop['id']};");
if (!$result_stopkeys) {
  echo "An stops keys retirieve error occured.\n";
  exit;
}
$name = "";
while ($stopkeys = pg_fetch_assoc($result_stopkeys)) {
echo htmlspecialchars(print_r($stopkeys,true));
$name .= htmlspecialchars($stopkeys['v']);
}
echo "</description>";
 echo "<name>$name</name>";
 
echo "<styleUrl>#target</styleUrl>";
echo "\n   <Point><coordinates> ";
                echo ($stop['longitude']/10000000).",".($stop['latitude']/10000000)."\n";
echo "        </coordinates> </Point>";
echo '</Placemark>';
}
 
echo "\n</Document></kml>\n";
?>