我正在处理一个php文件,该文件从mysql表生成一个kml文件,然后我可以使用谷歌地图。我有文件启动并运行但是,我在文本中遇到一些问题,这些问题应该出现在点击标记后弹出的气泡中。 首先,只有文本的第一部分出现[b_name],其次,我想格式化泡泡中的文本,但我的html标签只显示为文本。
我从中提取信息的表是一个视图,使用以下sql创建:
create view totalbaeir as
select syslur.sysla, hreppar.hreppur, baeir.b_name, baeir.lat, baeir.lng, baertyper.stjarna
from hreppar, syslur, baeir, baertyper
where (syslur.syslaid = hreppar.syslaid)
AND (baeir.hrepparid = hreppar.hrepparid) order by baeir.b_name;
这给了我一个包含以下字段的视图:
sysla (equivalent to f.x. a state)
hreppur (equivalent to f.x. a county)
b_name (farm name)
lat (latitude)
lng (longitude)
stjarna (farm-type, gives the value used to generate a style in the kml file).
这里可以看到php / kml文件生成的标记示例:http://hafdal.dk/index.php/da/kirker/kegnaes-kirke/9-test
这里可以看到php / kml输出:http://www.hafdal.dk/kml/phpsql_rakeltest1.php
如果您查看下面的php文件,您可以看到气泡中的文本是使用以下代码生成的:
$descText = htmlentities("<b>".$row['b_name']."</b>".$row['hreppur']);
但是如果你看一下气泡,只显示变量b_name,格式化不起作用。
我有什么想法可以解决这个问题吗?
这是我的php文件:
<?php
require('phpsqlajax_dbinfo.php');
// Opens a connection to a MySQL server.
$connection = mysql_connect ($server, $username, $password);
if (!$connection)
{
die('Not connected : ' . mysql_error());
}
// Sets the active MySQL database.
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected)
{
die('Can\'t use db : ' . mysql_error());
}
// Selects all the rows in the markers table.
$query = 'SELECT * FROM totalbaeir WHERE lat !=0';
$result = mysql_query($query);
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
// Creates the Document.
$dom = new DOMDocument('1.0', 'UTF-8');
// Creates the root KML element and appends it to the root document.
$node = $dom->createElementNS('http://earth.google.com/kml/2.1', '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);
// Creates the two Style elements, one for baer and one for hus, and append the elements to the Document element.
$baerStyleNode = $dom->createElement('Style');
$baerStyleNode->setAttribute('id', 'baerStyle');
$baerIconstyleNode = $dom->createElement('IconStyle');
$baerIconstyleNode->setAttribute('id', 'baerIcon');
$baerIconNode = $dom->createElement('Icon');
$baerHref = $dom->createElement('href', 'http://www.hafdal.dk/kml/torfhus.PNG');
$baerIconNode->appendChild($baerHref);
$baerIconstyleNode->appendChild($baerIconNode);
$baerStyleNode->appendChild($baerIconstyleNode);
$docNode->appendChild($baerStyleNode);
$husStyleNode = $dom->createElement('Style');
$husStyleNode->setAttribute('id', 'husStyle');
$husIconstyleNode = $dom->createElement('IconStyle');
$husIconstyleNode->setAttribute('id', 'husIcon');
$husIconNode = $dom->createElement('Icon');
$husHref = $dom->createElement('href', 'http://www.hafdal.dk/kml/torfhus2.PNG');
$husIconNode->appendChild($husHref);
$husIconstyleNode->appendChild($husIconNode);
$husStyleNode->appendChild($husIconstyleNode);
$docNode->appendChild($husStyleNode);
// Iterates through the MySQL results, creating one Placemark for each row.
while ($row = @mysql_fetch_assoc($result))
{
// Creates a Placemark and append it to the Document.
$node = $dom->createElement('Placemark');
$placeNode = $docNode->appendChild($node);
// Creates an id attribute and assign it the value of id column.
//$placeNode->setAttribute('id', 'placemark' . $row['id']);
// Create name, and description elements and assigns them the values of the name and address columns from the results.
$nameNode = $dom->createElement('name',htmlentities($row['name']));
$placeNode->appendChild($nameNode);
$descText = htmlentities("<b>".$row['b_name']."</b>".$row['hreppur']);
$descNode = $dom->createElement('description', '');
$cdataNode = $dom->createCDATASection($descText);
$descNode->appendChild($cdataNode);
$placeNode->appendChild($descNode);
$styleUrl = $dom->createElement('styleUrl', '#' . $row['stjarna'] . 'Style');
$placeNode->appendChild($styleUrl);
// Creates a Point element.
$pointNode = $dom->createElement('Point');
$placeNode->appendChild($pointNode);
// Creates a coordinates element and gives it the value of the lng and lat columns from the results.
$coorStr = $row['lng'] . ',' . $row['lat'];
$coorNode = $dom->createElement('coordinates', $coorStr);
$pointNode->appendChild($coorNode);
}
$kmlOutput = $dom->saveXML();
while (@ob_end_clean());
header('content-type:text/xml;');
echo $kmlOutput;
?>