不動産データの MySQL テーブルが与えられた場合、次の出力を含む KML ファイルを生成したいと考えています。
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<name>Property Address Pulled from Address Field</name>
<description>
Some descriptive data pulled from table inserted here.
</description>
<Point>
<coordinates>Latitude FROM Lat,Long FROM Lng</coordinates>
</Point>
</Placemark>
</Document>
</kml>
これは私がこれまでに持っているコードです。ご覧のとおり、上記のように KML を構成するループを記述するのに問題があります。どんな助けでも大歓迎です!
<?php
require("phpsqlgeocode_dbinfo.php");
// Start XML file, create parent node
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true; //This was added from the PHP Doc. Nice output.
// Creates the root KML element and appends it to the root document.
$node = $dom->createElementNS('http://www.opengis.net/kml/2.2', 'kml');
$parNode = $dom->appendChild($node);
// Creates a KML Document element and append it to the KML element.
$dnode = $dom->createElement('Document');
$docNode = $parNode->appendChild($dnode);
// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die("Not connected : " . mysql_error());
}
// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ("Can\'t use db : " . mysql_error());
}
// Search the rows in the markers table
$query = sprintf("SELECT * FROM markers");
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
header("Content-type: application/vnd.google-earth.kml+xml");
// Iterate through the rows, adding KML nodes for each
while ($row = @mysql_fetch_assoc($result)){
$dnode = $dom->createElement("Placemark");
$newnode = $docNode->appendChild($dnode);
$newnode = $newnode->createElement("Name");
$newnode = $newnode->createElement("Description");
$newnode = $newnode->createElement("Coordinates");
}
echo $dom->saveXML() . "\n";
?>