您好,我正在尝试在谷歌地图中制作一个公交路线查找器。谷歌地图v3 - 通过用户输入添加php生成的标记
到目前为止,我已经有了一个静态路线,可以在谷歌的“使用PHP/MySQL和谷歌地图”的帮助下在地图上显示。
这工作的PHP文件从数据库中提取数据并制作一个XML文件,然后谷歌映射JavaScript使用该XML数据制作标记/多段线。
我的版本:http://www.ykothari.co.uk/gmap-php/gmap-php.html
PHP代码:
<?php
require("dbserverinfo.php");
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
// Opens a connection to a MySQL server
$connection=mysql_connect ($dbserver, $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());
}
// Select all the rows in the markers table
$query = "SELECT * FROM bus109;";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<?xml version="1.0"?>' . "\n";
echo '<markers>' . "\n";
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<markers109 ';
echo 'stopname="' . parseToXML($row['stopname']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'service="' . $row['service'] . '" ';
echo 'stopid="' . $row['stopid'] . '" ';
echo '/>' . "\n";
}
// End XML file
echo '</markers>';
?>
现在我想添加一个搜索框供用户在巴士路线号码类型他们希望看到,所以当他们在搜索框中输入“1”时,php脚本只会获取该路由器的标记。我假设php文件中的“select * from table”正在获取数据。有没有一种方法可以在用户输入时修改此行,或者有其他方法来实现此目的?因此,该文件只能获取该路线的行数据,而不是整个数据库作为数据库的约50,000条目。
赞赏任何指向示例或教程的链接。