Add some friendly name/duplicate subsitution rules
[bus.git] / displaystops.kml.php
blob:a/displaystops.kml.php -> blob:b/displaystops.kml.php
--- a/displaystops.kml.php
+++ b/displaystops.kml.php
@@ -1,1 +1,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";

+?>