kml.php 767 B

123456789101112131415161718192021
  1. <?php
  2. header('Access-Control-Allow-Origin: *');
  3. header('Cache-Control: no-cache, must-revalidate');
  4. header('Content-type: application/xml');
  5. $dbh = new PDO("mysql:host=localhost;dbname=tasks", "root", "gc01mysql");
  6. $dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
  7. $q = $dbh->query("SELECT kunde, system, plz, ort FROM kunden");
  8. $cust = $q->fetchAll(PDO::FETCH_ASSOC);
  9. $doc = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"UTF-8\"?><kml xmlns=\"http://www.opengis.net/kml/2.2\" />");
  10. foreach($cust as $c) {
  11. $p = $doc->addChild("Placemark");
  12. $p->addChild("name", $c['kunde']);
  13. $p->addChild("description", $c['system']);
  14. $point = $p->addChild("Point");
  15. $point->addChild("coordinates", "-122.0822035425683,37.42228990140251,0");
  16. }
  17. echo $doc->asXML();